Forum Discussion
YO_CO
1 year agoFrequent Visitor
Dynamic rolling previous N months
Hi all, I'm looking for a way to show the rolling N months sum, and have the matrix table respond dynamically. For example if I choose Aug 2024 and 3 months, the matrix should only show JUN, ...
Anonymous
1 year agoNot applicable
Hi YO_CO ,
Here is my sample data:
I don't know how your calculated Calendar column is created, so I use this instead:
Then I create a parameter for choose month numbers:
Use this DAX to create a measure and put the measure into the matrix visual:
SUM_VALUE =
VAR _Parameter = SELECTEDVALUE(Parameter[Parameter])
VAR _CurrentMonth = MAX('Table'[Date])
VAR _PreviousMonth = EOMONTH(_CurrentMonth, -_Parameter)
RETURN
CALCULATE(
SUM('Table'[Value]),
ALL('Table'),
'Table'[Date] > _PreviousMonth && 'Table'[Date] <= _CurrentMonth
)
Then use this DAX to create another measure as a filter:
Measure =
VAR _Parameter = SELECTEDVALUE(Parameter[Parameter])
VAR _CurrentMonth = MAXX(FILTER(ALL('Table'), 'Table'[Flag] = "IsCurrentMonth"), 'Table'[Date])
VAR _PreviousMonth = EOMONTH(_CurrentMonth, -_Parameter)
RETURN
IF(
MAX('Table'[Date]) > _PreviousMonth && MAX('Table'[Date]) <= _CurrentMonth,
1,
0
)
Make the settings as shown in the figure below:
Output:
If I choose 3 months:
If I choose 13 months:
Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.