Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
abhaysingh
Specialist II
Specialist II

Set Expression Help

Hi ,

i have to show Max Month Sales, previous month sale and previous to previous month sales.

i created 3 variables

vMaxMonth = max(Month)                /// month value are in number

vlastMonth = Max(Month)-1

vlast2lastMonth = Max(Month)-2

now i am using variable in this way.

=sum({< Month = {$(vMaxMonth)}>}sales

=sum({< Month = {$(vlastMonth )}>}sales

please correct me it is not working

11 Replies
Not applicable

Try this..

vMaxDate=max(Date)

vMaxMonth = month(vMaxDate)             

vlastMonth =addmonths(vMaxDate,-1)

vlast2lastMonth =addmonths(vMaxDate,-2)

I assume there is a Date column

abhaysingh
Specialist II
Specialist II
Author

what would be the syntax??

Not applicable

Let the expressions be same.. just change the variable definitions

Not applicable

this worked:

vMonthMax: =max(month)

vMonthMax1: =max(month) - 1

vMonthMax2: =max(month) - 2

sum({<month = {$(vMonthMax)}>} sum)

sum({<month = {$(vMonthMax1)}>} sum)

sum({<month = {$(vMonthMax2)}>} sum)

abhaysingh
Specialist II
Specialist II
Author

max month working but last and last 2 last month not working

abhaysingh
Specialist II
Specialist II
Author

Alexandra, this is the same i was doing but not working.. not able to understand why

Not applicable

can you share the sample qvw file? 'cos it worked for me perfectly

Not applicable

Abhay,

I think if you change the definition of these variables to

vlastMonth =month(addmonths(vMaxDate,-1))

vlast2lastMonth =month(addmonths(vMaxDate,-2))

..then it will work. Just try and let me know

Regards,

Dawar

ankitaag
Partner - Creator III
Partner - Creator III

Refer the attached application

You just need to create 2 variables for MinDate and Max Date