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

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 )

Google photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s