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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Lokesh_5045
Creator
Creator

Compare same values in different months

I have the data like below for all months.

ID Month Value
A December 1
B December 2
C December 3
D December 4
A November 5
B November 2
C November 1

 

I need to flag only present month IDs by comparing with previous month same IDs. I cannot do this in script since my previous month selection is dynamic from drop down list. Suppose if I select November from drop down list, the data should appear like below.

ID Month Value Flag
A December 1 Decrease
B December 2 Same
C December 3 Increase
D December 4 New

 

Flagging is based on comparison of value of same ID of selected month.
{December} C   >   {November} C -----> Increase

Labels (5)
1 Solution

Accepted Solutions
AronC
Partner - Creator II
Partner - Creator II

If you dont want to use monthId you could do everything in the set expression as in below. I prefer flags though because it makes everything easier and more clear. But you can use the below expression.

if(Sum(Value)>sum({<Month={"$(=month(addmonths(max(Date),-1)))"}>}Value),'increased','decreased')

 

If you want to show the selected month in the table as well you could just use an expression.

Expression for showing the month: month(Min(Date))

 

Good luck and please mark as solution if it works out for you.

 

View solution in original post

3 Replies
AronC
Partner - Creator II
Partner - Creator II

If you show the fields ID, Value and Flag and leave out month from your table, you can use this expression

if(Sum(Value)>sum({<Month, MonthId={"$(=max(MonthId)-1)"}>}Value),'increased','decreased')

For it to work you need to create Ids for your month backend. If you have a calendar table, then you just create you id field like:

load *, autonumber(Month) as MonthId

Hope it helped you out.

Lokesh_5045
Creator
Creator
Author

@AronC , Thank you for your reply.
My current month is max of my date field and I have saved into a variable. In present example, it is December.
My selected month is based on month input from variable input from front end. In present example, it is November.
I shouldn't change my backend script and my current visualization.
Please suggest me. This can be done using set analysis imo. But, I am not getting any ideas here.

AronC
Partner - Creator II
Partner - Creator II

If you dont want to use monthId you could do everything in the set expression as in below. I prefer flags though because it makes everything easier and more clear. But you can use the below expression.

if(Sum(Value)>sum({<Month={"$(=month(addmonths(max(Date),-1)))"}>}Value),'increased','decreased')

 

If you want to show the selected month in the table as well you could just use an expression.

Expression for showing the month: month(Min(Date))

 

Good luck and please mark as solution if it works out for you.