Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Ipsita20191
Contributor III
Contributor III

Get last 12 months rolling data based on Month selection

Hi Folks,

I need one help . I have one Year and a Month Filter as a drop down.

If I select 2023 as a Year and Feb as a month from drop down selection, 

Sum (Sales) : should return data from 2023 Feb to 2022 Feb (Last 12 months).

Note : Month drop down has been declared as a varibale : $(vMonth)

Can you please help on that ?

Thanks

2 Replies
Sabrina_V
Partner - Creator II
Partner - Creator II

You can do it in the set analysis using the function AddMonth (Month, -12)

srchagas
Creator III
Creator III

Hi

I recommend you  to have DATE in numeric format, because it make the thinks easy to make the set analysis.

Left assume you have 01/02/2023 selected, so its this as number you create a variable like this:
Ps; I recommend 2 variables: 

vL.MaxDate = Num(Floor(Max(YOUR_DATE_FIELD)))
vL.LastYearDate = Num(Floor(Max(YOUR_DATE_FIELD))) - 365 

Once you have this 2 variables you set analysis will be

//New Set Analysis Way
{< YOUR_DATE_FIELD =,  YOUR_DATE_FIELD = ">=$(vL.LastYearDate) <=$(vL.MaxDate) >}  Sum(Sales)

//Old Set analysis Way
Sum({< YOUR_DATE_FIELD =,  YOUR_DATE_FIELD = ">=$(vL.LastYearDate) <=$(vL.MaxDate) >} Sales)

Don't forget to add all your possible date fields to be ignored using: FIELD =, in the set analysis, because then you saying:

Ignore what the user select and calculate use  what i sent to you.

 

this works 100%

 

srchagas_0-1685952161054.png