Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
jim_chan
Specialist
Specialist

How to create a Rolling 13 months dimension and use in a bar chart?

Hi there, 

I want to create a rolling 13 months dimension , for a bar chart. but i dont know how to write the script.

Example: no is Nov 2022. so by putting this rolling 13 months, it will be Nov2021 - Nov 2022 ( 13 months right?) 

expression: sum(sales)

Please help guys!

jim_chan_0-1668509287339.png

 

1 Solution

Accepted Solutions
vinieme12
Champion III
Champion III

Instead of YearMonth you need to use your Datefield 

 

Sum({<datefield = {">=$(=Date(AddMonths(Max(datefield),-12))) <=$(=Date(Max(datefield)))"}>} SUM_NET_SALES)

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.

View solution in original post

2 Replies
jim_chan
Specialist
Specialist
Author

I tried to use this expression. but it only came out 2022 jan - 2022 Nov. is wrong.

jim_chan_0-1668510851288.png

Dimension YearMonth

Expression: Sum({<YearMonth = {">=$(=AddMonths(Max(YearMonth),-12)) <=$(=Max(YearMonth))"}>} SUM_NET_SALES)

and in the loading script, it shows 

jim_chan_1-1668510952685.png

please help!

vinieme12
Champion III
Champion III

Instead of YearMonth you need to use your Datefield 

 

Sum({<datefield = {">=$(=Date(AddMonths(Max(datefield),-12))) <=$(=Date(Max(datefield)))"}>} SUM_NET_SALES)

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.