Forum Discussion
murphm6
Helper II
3 years agoHelp calculating 12 month trailing sum in table
Hi all, i want to calculate a twelve month trailing sum of the volume column for each individual prod pkg code - how can i do this? I've tried doing CALCULATE(SUM('Table' [Vol(CUR]), DATESINPERIO...
Greg_Deckler
Community Champion
3 years agomurphm6 Try this, just use SUMX instead of AVERAGEX: Better Rolling Average - Microsoft Power BI Community
Also, it's not working because it's a single table data model which CALCULATE doesn't handle very well:
- murphm63 years ago
Helper II
I know the result for this is a measure - is there any way to get this value as a column? So for each row, the column would be a sum of the volume for the prior 12 months?
- Greg_Deckler3 years ago
Community Champion
murphm6 It's almost the exact same formula, you just have to drop the MAX aggregation:
Better Rolling Sum = VAR __EndDate = 'Table'[Date] VAR __3MonthsAgo = EOMONTH(__EndDate, -12) VAR __StartDate = DATE(YEAR(__3MonthsAgo), MONTH(__3MonthsAgo), 1) VAR __Table = SUMMARIZE( FILTER(ALL('Table'),[Date]>=__StartDate && [Date]<=__EndDate), 'Table'[Month], "__Value",SUM('Table'[Value]) ) RETURN SUMX(__Table,[__Value])- murphm63 years ago
Helper II
So i think this is on the right track but it's not accounting for each prod-pkg code, rather it's just summing the entire thing. What can I add to ensure it also considers the prod-pkg-code column?