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: 
Saurabh07
Contributor III
Contributor III

Line chart for past three months based on date selected in filter

Hello Gurus,

I have some requirement in my Qlik app. I have below dataset to work with;

MonthCountryValue
01-01-2020USA50
01-01-2020India137
01-01-2020China118
01-01-2020Austria51
01-01-2020Japan144
01-02-2020USA147
01-02-2020India61
01-02-2020China70
01-02-2020Austria93
01-02-2020Japan79
01-03-2020USA80
01-03-2020India99
01-03-2020China102
01-03-2020Austria122
01-03-2020Japan61
01-04-2020USA87
01-04-2020India51
01-04-2020China67
01-04-2020Austria76
01-04-2020Japan88
01-05-2020USA112
01-05-2020India102
01-05-2020China108
01-05-2020Austria94
01-05-2020Japan113

 

Now I want to see a 3 month trend for Top 2 countries in line chart. To get top 2 countries I am using mentioned expression;

=aggr(if(rank(sum(Value))<3,Country),Country)

But I am not able to figure out on how to get the trend for only past three months from the date selected in filter. eg. If I select '01-05-2020' in filter the graph should show only the months of '01-05-2020','01-04-2020' and '01-03-2020'. Similarly if I select '01-04-2020' in the filter, the graph should show only the months of '01-04-2020', '01-03-2020' and '01-02-2020'

Saurabh07_0-1604502281522.png

Can anyone please help me with this? Some assistance here would be highly appreciated! 

 

 

5 Replies
lironbaram
Partner - Master III
Partner - Master III

hi 
try this expression : 

sum({<Month={">=$(=addmonths(max(Month),-2))"}>}Value)
Saurabh07
Contributor III
Contributor III
Author

Hello  @lironbaram , Thank you for the expression. But there is a small issue with this, it works absolutely fine when Max date (01-05-2020) is selected.

Saurabh07_0-1604556871392.png

But if I select '01-04-2020', the graph shows trend for four months instead of three. Ideally '01-05-2020' should be eliminated from the trend since it comes after '01-04-2020'. The ideal result I want to see here is past 3 months trend only from the selected month.

Saurabh07_1-1604556901134.png

 

MayilVahanan

HI @Saurabh07 

Try with below

sum({<Month={">=$(=addmonths(max(Month),-2))<=$(=addmonths(max(Month),0))"}>}Value)

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
Saurabh07
Contributor III
Contributor III
Author

@MayilVahanan  Many thanks. This has almost worked except for one more condition. Can you also help me figure out on how do I accommodate the state in my expression for Date filter. eg. If I create an alternate state [Current] and apply it to the filter, then this expression wont work. It would be a great help if you can help me resolve this issue?

MayilVahanan

HI @Saurabh07 

Try like below. 

sum({Current<Month={">=$(=addmonths(max({Current}Month),-2))<=$(=addmonths(max({Current}Month),0))"}>}Value)

Please go through before link about Alternate state.

Link: https://help.qlik.com/en-US/qlikview/April2020/Subsystems/Client/Content/QV_QlikView/Examples%20of%2...

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.