Power BI & DAX Tutorial: How to Calculate Rolling (Moving) Average on Non-Contiguous Dates

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))

2 thoughts on “Power BI & DAX Tutorial: How to Calculate Rolling (Moving) Average on Non-Contiguous Dates

  1. 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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s