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 Date, Variables & Set Analysis

Here is what I am trying to accomplish:  Use a variable to get the max(Date) and return that amount only in KPI Object basically to get the sum of the max(date) and ignore the other values

I have data like this

Date:                    Sum( Dollars)

3/31/2017              1500.00

2/28/2017                100.00

1/31/2017                400.00

I have it working for hardcoding the value but created a variable called vMaxDate and I have tried variations on this but to no success.

Sum({1<AS_OF_DT = {"03/31/2017"}>} SALES)

Any help would be greatly appreciated!

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Do you mean ignore the selection in the calculation of your max date?

That would be in your variable declaration.  Something like:

vMaxDate=date(max({1}AS_OF_DT),'M/D/YYYY')

View solution in original post

9 Replies
Anonymous
Not applicable
Author

Various versions I've tried and just seems to either have syntax incorrect or evaluating the vMaxDate as number not date

Sum({1<AS_OF_DT={$(vMaxDate)}>} SALES)

vMaxDate = Max(AS_OF_DT)

Anil_Babu_Samineni

How is your environment looks like for DateFormat?

Can you change it to

SET DateFormat='MM/DD/YYYY';

from

SET DateFormat='DD-MM-YYYY';

Then Try ??

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
Anonymous
Not applicable
Author

try


vMaxDate=date(max(AS_OF_DT),'M/D/YYYY')


and


Sum({1<AS_OF_DT={'$(vMaxDate)'}>} SALES)

Anonymous
Not applicable
Author

I set them like this:

SET DateFormat='MM/DD/YYYY';

SET TimestampFormat='MM/DD/YYYY h:mm:ss[.fff] TT';

Originally they were 'M/D/YYY';

Anonymous
Not applicable
Author

I tried that and several combinations on that.  I do have a master calendar that I just added so I may try going that route.

This works that I've used but can't get the selection part to work but it does for other KPI's that I've created

Works:  sum(if(AS_OF_DT=vMaxDate,Sales))/1000000000 but the selecting dimensions changes the values and for this one I would not want it to

Another KPI on that sheet works :Sum({1<AS_OF_DT_YYYY={$(vCurrentYear)}>} SALES)/1000000000

Will continue to work on this but thanks for responses.

Anonymous
Not applicable
Author

Do you mean ignore the selection in the calculation of your max date?

That would be in your variable declaration.  Something like:

vMaxDate=date(max({1}AS_OF_DT),'M/D/YYYY')

Anonymous
Not applicable
Author

This data is by month end only trending back 3 years so I have a variable set to pull max(AS_OF_DT) in this case 3/31/2017.  I also have variable based off that variable that would pull out just the year(vMaxDate)-1 to pull all of 2016 etc for 2015...sample made up data but principle is here and I have most of this working.

If you think of it this way one set KPI's to never change at the company level, and another set KPIs to change with the selection the user has, in this case they would most likely select the BUSAREA they are interested in but would still see the company level KPIs above them.

Maybe I'm overcomplicating this.

   

KPIAS_OF_DTValuesBehavior Desired
Most Recent Month Sales03/31/2017$509,918No change when selections made
PREV YEAR SALESAll 2016$323,767Change with selection
2 YEAR PREV SALESAll 2015$483,835Change with selection

   

AS_OF_DTBUSAREASALESTax
03/31/2017A$37,313$933
03/31/2017B$52,643$1,316
03/31/2017C$1,193$30
03/31/2017D$81,166$2,029
02/28/2017A$36,813$920
02/28/2017B$52,663$1,317
02/28/2017C$1,180$29
02/28/2017D$80,497$2,012
01/31/2017A$35,773$894
01/31/2017B$51,476$1,287
01/31/2017C$1,160$29
01/31/2017D$78,041$1,951
12/31/2016A$34,568$864
12/31/2016B$50,380$1,260
12/31/2016C$1,123$28
12/31/2016D$75,998$1,900
11/30/2016A$34,498$862
11/30/2016B$50,330$1,258
11/30/2016C$1,158$29
11/30/2016D$75,711$1,893
10/31/2015A$34,302$858
10/31/2015B$49,800$1,245
10/31/2015C$1,121$28
10/31/2015D$74,448$1,861
09/30/2015A$34,722$868
09/30/2015B$50,645$1,266
09/30/2015C$1,121$28
09/30/2015D$76,047$1,901
08/31/2015A$34,402$860
08/31/2015B$50,522$1,263
08/31/2015C$1,128$28
08/31/2015D$75,577$1,889
Anonymous
Not applicable
Author

This should have worked

Sum({1<AS_OF_DT={'$(vMaxDate)'}>} SALES)


But you could also try

Sum({<AS_OF_DT={'$(vMaxDate)'}>} TOTAL SALES)


or


Sum({<AS_OF_DT={'$(vMaxDate)'},BUSAREA=>} SALES)

Anonymous
Not applicable
Author

Thanks Wallo it was an issue I was having with variable and works much appreciated!