Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
ELZ
Contributor
Contributor

Rolling 12 months sales

Hi,

I have read many questions here about rolling measures and tried different solutions but still cannot get my table right.

I have a simple dataset attached here. There is three different products with sales by month (YYYY-MM). I have loaded this data in Qlik sense like this:

ELZ_0-1665062616490.png

Then I tried many of different codes to get that sales rolling 12 month. This is the last one I tried:

ELZ_2-1665063372922.png

 

Avg({<YearMonth = {"$(='>=' & Date(MonthStart(Max(YearMonth), -12), 'YYYY-MM') & '<=' & Date(Max(YearMonth), 'YYYY-MM'))"}>}Sales)

But somehow I always manage to get only one month sales by YearMonth and my goal is to get it show sales in table like this:

ELZ_4-1665063493950.png

So the table where for each row there is Product, YearMonth and the sum of sales from this YearMonth 12 months back. Is there something I need to do in the loading code? Or how is it possible to get that sum of twelve month showing by month?

 

 

Labels (1)
1 Reply
Mark_Little
Luminary
Luminary

Hi @ELZ 

It will be possible to get in Set Analysis, But i always tend to make a flag in Script for thing like this and normally make it part of my calendar. 

Here is what i use, would need to be tweaked.

IF(TempDate <= MONTHSTART(TODAY(1))-1 AND TempDate >= ADDMONTHS(MONTHSTART(TODAY(1)),-12),1) AS F_ROLLING_12_MONTHS,