Rolling Average calculations are easy as long as you don’t have to worry about gaps in your dates for which you do not have any transactions. In this tutorial, I boldly take on this challenge and successfully complete the calculation that is able to find the last five days on which the selected product had sales, and then average those sales out to get the rolling (or moving) average.
The Power BI Desktop file can be downloaded here.
The calculation is below:
Rolling 5 Last Days Sales Average =
var lastFiveDaysOfSales = CALCULATETABLE(
TOPN(5,
SUMMARIZE( Sales,
Sales[Date],
“Sales”,
SUM(Sales[Amount])
), Sales[Date], DESC
)
,
FILTER( ALL(‘Date'[Date]),
‘Date'[Date] <= SELECTEDVALUE(‘Date'[Date])
)
)
return DIVIDE(SUMX(lastFiveDaysOfSales, [Sales]), COUNTROWS(lastFiveDaysOfSales))
This is very useful, but how would this be written for a moving average of 12 months?
Hello, I am struggling to covert windowstdv Tableau code to power BI.
Basically looking to plot lower bound and upper bound using moving standard deviation.