Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

bhavvibudagam
Contributor II

Last 12 months restriction

Hi Experts,

Can any one please help me on below requirement.

In the YearMonth Field I have records from 2017/01 to 2018/02.

Here I have to restrict last 12 months

Sum({<YearMonth={">=$(=Max(YearMonth)-12) <$(=Max(YearMonth))"}>}Sales)

with the above expression when I have selected 2018/01 then getting last 12 months from 2017/01 to 2017/12

but when i have selected 2018/02 then getting last 13 months from 2018/01 to 2017/01 but need to get 2018/01 to 2017/02.

How to get this. Please help me on it. Please find the attached Document.

201812.png

Thanks in advance

1 Solution

Accepted Solutions
OmarBenSalem
Esteemed Contributor

Re: Last 12 months restriction

It's not taking into consideration the >=$(=Max(YearMonth)-12) part

change ur expression as follow:

=Sum({<YearMonth={">=$(=date(addMonths(Max(YearMonth),-12),'YYYY/MM')) <$(=Max(YearMonth))"}>}Sales)

result:

Capture.PNG

Capture.PNG

see the attached app:

3 Replies
OmarBenSalem
Esteemed Contributor

Re: Last 12 months restriction

It's not taking into consideration the >=$(=Max(YearMonth)-12) part

change ur expression as follow:

=Sum({<YearMonth={">=$(=date(addMonths(Max(YearMonth),-12),'YYYY/MM')) <$(=Max(YearMonth))"}>}Sales)

result:

Capture.PNG

Capture.PNG

see the attached app:

MVP
MVP

Re: Last 12 months restriction

Sum({<YearMonth={">$(=Max(YearMonth)-12) <$(=Max(YearMonth))"}>}Sales)

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
OmarBenSalem
Esteemed Contributor

Re: Last 12 months restriction

No, that won't do it Jonathan;

in fact, in this case:

=date(Max(YearMonth)-12,'YYYY/MM') would go back by 12 days:

Capture.PNG

Community Browser