Forum Discussion
Rolling 12 Month Average
Hello everyone, I need assistance correcting my formula for a 12-month rolling average. I am trying to find out the monthly spending of Amazon and Company Cards (Bento), then find out the monthly average per store. I am summing Amazon and Bento Spend based on status = 'Complete' and not 'Declined' See the following 3 measures:
- Amazon Sum = CALCULATE(sum('All Amazon and Bento'[Amount]), 'All Amazon and Bento'[Data Table] = "Amazon", 'All Amazon and Bento'[Order Status] <> "Cancelled")
- Bento Sum = CALCULATE(Sum('All Amazon and Bento'[Amount]), 'All Amazon and Bento'[Data Table] = "Bento", 'All Amazon and Bento'[Order Status] = "Complete")
- Total Sum = 'All Amazon and Bento'[Amazon Sum] + 'All Amazon and Bento'[Bento Sum]
- 12-Month Average per Store =CALCULATE (AVERAGEX (VALUES ( 'All Amazon and Bento'[Year & Month] ),DIVIDE ( [Total Sum], COUNT( Names_Table_Amazon_and_Bento[Number of Stores] ) )),DATESINPERIOD (Date_Value[DateValue],MAX ( 'All Amazon and Bento'[Order Date] ),-12,MONTH))
Thank you, I actually used that site to help try and diagnose my issue but still couldn't figure out my error. My formula appears to be identical with the expectation he uses Variables. Also, my tables with the sales do not have daily sales, that's the only difference I can think of, but in my datesinperiod portion, I am using a continuous date table regardless.
I figured it out, I was trying to make the 12-month moving average a calculated column when it should be a measure. Thank you for helping me navigate this!
4 Replies
- some_bihCommunity Champion
Hi james_pease check master link https://www.sqlbi.com/articles/rolling-12-months-average-in-dax/ I hope this help
- james_peaseHelper III
I figured it out, I was trying to make the 12-month moving average a calculated column when it should be a measure. Thank you for helping me navigate this!
- james_peaseHelper III
Thank you, I actually used that site to help try and diagnose my issue but still couldn't figure out my error. My formula appears to be identical with the expectation he uses Variables. Also, my tables with the sales do not have daily sales, that's the only difference I can think of, but in my datesinperiod portion, I am using a continuous date table regardless.
- some_bihCommunity Champion
Hi james_pease if possible share your pbi file to try to see details.