# Rolling Averages In Power BI

Getting a rolling average should be an native function in Power BI. However maybe at the time you read this, there will already be a a feature added. However, in the meantime lets dive into dynamic rolling average using Power BI.

Here are the list of functions will be using the to create our calculation:

• SUM
• CALCULATE
• LASTDATE
• DATESINPERIOD
• DISTINCTCOUNT

There are two points to this formula:

1. Calculating the sum of the value in the period
2. Calculating the count of days in the period
3. Dividing these two calculations

Calculating the Sum during the period

CALCULATE(SUM(VALUE), DATESINPERIOD(DATE,START DATE, NUMBER OF INTERVALS, INTERVAL)

Calculating the count of day in the period

CALCULATE(DISTINCTCOUNT(DATE), DATESINPERIOD(DATE,START DATE, NUMBER OF INTERVALS, INTERVAL)

Formula for a 28 day average

To make this much cleaner you can use variables that will allow achieve the same affect.

Dynamic Power BI Rolling Average with DAX Parameters #### Gaelim Holland

Subscribe
Notify of Inline Feedbacks Ras
2 years ago

Thank you Cathy
2 years ago

Hello i tried this but it is returning blank ☹️. What could be the problem? Thank you in advance for your response! Todd
2 years ago

Thanks! Struggle with this until I ran across your solution. Leny
2 years ago

This is great, but the rolling average takes the proceeding data, is there a way to make it look backwards instead of forwards? MaxB
2 years ago

Hi, very instructive post, yet I am getting the error

A function ‘DATESINPERIOD’ has been used in a True/False expression that is used as a table filter expression. This is not allowed.

how can we avoid this? Anusha
28 days ago

Hi, Need help with the following question
For each product, create data as a moving average of the last 4 months.
For example: United States 37101 April, May, June, July are 1683,1668,776,1885. Predict Aug as Average of the 4, then use average of May, June July, Aug as September. And a slider that can be used to do -20% to +20%. Where we cn check forecast in case we go -1% of the moving average or 5% of the moving average.
Thanks