Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Max and Min Value with Dates

Dear Experts,

 

I have this table

productsubproducttypebucketNewMoBvintagevintageYrMonNewMOBPercent
CDNPBRFP1101-01-2015241692.74%
CDNPBRFP1101-02-2015241702.03%
CDNPBRFP1101-02-2016241821.40%
CDNPBRFP1101-06-2017241981.20%
CDNPBRFP1101-07-201724199

1.40%

 

I need this output

productsubproducttypebucketNewMoBvintagevintageYrMonNewMOBPercentMinValueMinDateMaxValueMaxDateAvgValue
CDNPBRFP1101-01-2015241692.74%1.20%01-06-20172.74%01-01-2015

1.76%

 

Trying a script in load editor but does not work

 

Thank you in advance 🙂

 

Labels (2)
2 Replies
Ashvi01
Contributor
Contributor

Hi,

Maybe try something along this line. I have done something similar with a 13 month trend to find min and max value. I have tweak it a bit but might need further amendments to make it work to your scenario. if you have year and month selection you might have to exclude them to make it work

 

min({<Date={">=$(=addMonths(max(vintage),-1)) <= $(=max(vintage))"}>} aggr (sum({$<DateValue={">=$(=addMonths(max(vintage),-1)) <= $(=max(vintage))"}>} NewMOBpercent),Date))

 

 

rubenmarin

Hi, one easy way can be loading it different times to flag records using peek to check if there is the same key, and do a final join to have all together, ie:

tmpData:
LOAD *, product &'_'&subproduct... as keyField resident/from...;

tmpRecordToKeep:
LOAD *, If Peek(keyField )=keyField , 0 ,1) as flagKeep
resident tmpData order by keyField, vintage;

tmpMaxValue:
LOAD keyField, vintage as MaxDate, NewMOBPercent as MaxValue,
If Peek(keyField )=keyField , 0 ,1) as flagMax
resident tmpData order by keyField, vintage, NewMOBPercent desc;

tmpMinValue:
LOAD keyField, vintage as MinDate, NewMOBPercent as MinValue,
If Peek(keyField )=keyField , 0 ,1) as flagMin
resident tmpData order by keyField, vintage, NewMOBPercent;

tmpAvg:
LOAD keyField, Avg(NewMOBPercent) as AvgValue
resident tmpData group by keyField;

Final:
LOAD * resident tmpRecordToKeep where flagKeep =1;
join LOAD keyField, MaxDate, MaxValue resident tmpMaxValue where flagMax=1;
join LOAD keyField, MinDate, MinValue resident tmpMinValue where flagMin=1;
join LOAD keyField, AvgValue resident tmpAvg;

DROP tables tmp...;