Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Calculate sales for last N months

I have a variable created to calculate the number of months back from which I need to calculate the sales.I also have sales listed by months.

For example, if n is 6, I need to calculate the sales from july 2014.

I tried several expressions but unable to seem to get it right. Can someone please help ?

11 Replies
Not applicable
Author

hi

I use the following expression, but there is a problem, when I select Month=2, the result only show which belong to Month 2, not the rolling result.

vBegin=Num(date(Addmonths(Date#(Max(MonthKey),'YYYYMM'),-11),'YYYYMMDD'),'#,##0')

vEnd=Num(Date(Max(DateDate),'YYYYMMDD'),'#,##0')

Count({<Month={$(vCurrentMonth)},Key={"<=$(vEnd)>=$(vBegin)"}>}Machine

prabhuappu
Creator II
Creator II

Hi,

Try changing the variable expression as below. Omitted the month selection from calculation.

vBegin=Num(date(Addmonths(Date#(Max({<Month=>}MonthKey),'YYYYMM'),-11),'YYYYMMDD'),'#,##0')

vEnd=Num(Date(Max({<Month=>}DateDate),'YYYYMMDD'),'#,##0')

Regards,

Prabhu Appu