Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

wajihakhan
New Contributor II

Last 2 months with current selected month

Hi,

I want last two months along with current selected month in bar chart.

like selected month is Jan and year is 2018. so i want Jan 2018, Dec 2017, Nov 2017.

I have separate year field and separate month field and i am using set analysis but not getting what i want.

Please help.

Thanks

6 Replies
YoussefBelloum
Esteemed Contributor

Re: Last 2 months with current selected month

Hi,

Create a MonthYear field and use this expression:

sum({< MonthYear={">=$(=AddMonths(max(MonthYear),-3)) <=$(=max(MonthYear))" }>} your_measure)

zebhashmi
Valued Contributor

Re: Last 2 months with current selected month

I second

driving from Selection use this.

sum({< MonthYear={">=$(=(MonthYear-2)) <=$(=MonthYear)" } >}your_measure)

Thanks

YoussefBelloum
Esteemed Contributor

Re: Last 2 months with current selected month

Hi,

MonthYear field is Month&Year concatenated field

So, for 012018 for example, MonthYear -2 = 012016

zebhashmi
Valued Contributor

Re: Last 2 months with current selected month

Yes Thanks!

so he just have to remove Max to drive it from Selection.

YoussefBelloum
Esteemed Contributor

Re: Last 2 months with current selected month

You make me think, here is the new (tested) one:

sum({< MonthYear={">=$(=Date(AddMonths(Date#(MonthYear,'MMYYYY'),-2),'MMYYYY')) <=$(=Date(Date#(MonthYear,'MMYYYY'),'MMYYYY'))" }>} your_measure)

zebhashmi
Valued Contributor

Re: Last 2 months with current selected month

Sounds good! Should be Marked Correct Answer Thank You for Sharing