Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Jodallen123
Helper I
Helper I

Rolling average with blanks present

Hi, 

 

I am trying to create a 4 week rolling average measure. 

 

Below is what I have so far and it works on my sales data, but for some reason I can't seem to make it work on my budget data (monthly value split out over all weekdays), the budget-table is connected to the master time table on the date-column. 

 

( I made the measure a 10 day average just because it was easier to check the result)

 

4davg_ratioBU =
VAR MaxVisibleDate = MAX('Master Time Table'[Date])
VAR RollingWindow =
    DATESINPERIOD('Master Time Table'[Date], MaxVisibleDate, -10, DAY)
RETURN
    AVERAGEX(
        RollingWindow,
        COALESCE([Budget], 0)
    )
 
The data looks like this:
 
DateBudgetCurrent measureSum 10 days BUActual 10 day avgImplied denominator
2025-01-0160.61   
2025-01-0261.22   
2025-01-0361.84   
2025-01-0401.84   
2025-01-0501.84   
2025-01-0662.45   
2025-01-0763.06   
2025-01-0863.67   
2025-01-0964.29   
2025-01-1064.90484.89.80
2025-01-1104.29424.29.80
2025-01-1203.67363.69.80
2025-01-1363.67363.69.80
2025-01-1464.29424.29.80
2025-01-1564.90484.89.80
2025-01-1664.90484.89.80
2025-01-1764.90484.89.80
2025-01-1804.29424.29.80
2025-01-1903.67363.69.80
2025-01-2063.67363.69.80
2025-01-2164.29424.29.80
2025-01-2264.90484.89.80
2025-01-2364.90484.89.80
2025-01-2464.90484.89.80
2025-01-2504.29424.29.80
2025-01-2603.67363.69.80
2025-01-2763.67363.69.80
2025-01-2864.29424.29.80
2025-01-2964.90484.89.80
2025-01-3064.90484.89.80
2025-01-3164.90484.89.80
2025-02-0104.29424.29.80
2025-02-0203.67363.69.80
2025-02-03114.20414.19.77
2025-02-04115.33525.29.75
2025-02-05116.47636.39.74
2025-02-06116.99686.89.72
2025-02-07117.52737.39.71
2025-02-0806.90676.79.70
2025-02-0906.29616.19.70
2025-02-10116.81666.69.68
2025-02-11117.95777.79.68
2025-02-12119.09888.89.68
2025-02-13119.09888.89.68
2025-02-14119.09888.89.68
2025-02-1507.95777.79.68
2025-02-1606.81666.69.68
2025-02-17116.81666.69.68
2025-02-18117.95777.79.68
2025-02-19119.09888.89.68
 
Any ideas why my measure give me incorrect values? Does it have to do with the 0:es on weekends? I tried the measure with no 0es on the weekends but it made no difference. 
 
Any help is much appreciated!  
1 ACCEPTED SOLUTION
sjoerdvn
Super User
Super User

Update:
I ran a test with the sample data you provided, and your 10 days rolling average measure actually provides the right values. Or do you want a different beviour, for example exclude non working days? .
Anyway, there is no need to use AVERAGEX here, so for performance I would use code like below.

4davg_ratioBU= 
VAR MaxVisibleDate = MAX('Master Time Table'[Date])
VAR RollingWindow =
    DATESINPERIOD('Master Time Table'[Date], MaxVisibleDate, -10, DAY)
RETURN
    DIVIDE(CALCULATE([Budget], RollingWindow), COUNTROWS(RollingWindow))

 

View solution in original post

9 REPLIES 9
sjoerdvn
Super User
Super User

Update:
I ran a test with the sample data you provided, and your 10 days rolling average measure actually provides the right values. Or do you want a different beviour, for example exclude non working days? .
Anyway, there is no need to use AVERAGEX here, so for performance I would use code like below.

4davg_ratioBU= 
VAR MaxVisibleDate = MAX('Master Time Table'[Date])
VAR RollingWindow =
    DATESINPERIOD('Master Time Table'[Date], MaxVisibleDate, -10, DAY)
RETURN
    DIVIDE(CALCULATE([Budget], RollingWindow), COUNTROWS(RollingWindow))

 

Hi, that gives me the same value as my current measure, but maybe your version is more efficient. However I don't think it's right? In my dataset above if you look at 2025-01-10, should the value not be 4.8? Not 4.9?

 

Jodallen123_1-1744025705163.png

 

 

I don't think I need to exclude non-working days. 

My guess is that the daily budget is not 6.00 for January, but more to the tune of 6.13, that would explain the numbers. Please check the formatting you are using. Or are you (re)calculating the daily budget in that measure?

I am an idiot, you're absolutely right! 

Yes, that value should be 4.80. In my model it is, using your measure and your dates and budget values; so clearly something else is happening.
So I would check the definition of that [Budget] measure, and the relationship between date table and budget data table.

Okay! 

 

The measure looks like this and and is connected to the master time table on a date column (one to many from the master time table), it should be a really straight forward model, or at least so I thought... Any ideas what could be going wrong with this measure? 

 

#NetSalesPVBU = CALCULATE( SUM( SalesBudget[DailyValue]), SalesBudget[SubCategory] = "Budget" )
sjoerdvn
Super User
Super User

Hard to say what's going on in your Model. [Current measure Sum 10 days] is also not returning the right values for the first 10 days. I assume [Budget] is a measure. Can you provide that definition?

bhanu_gautam
Super User
Super User

@Jodallen123 , Try using

4davg_ratioBU =
VAR MaxVisibleDate = MAX('Master Time Table'[Date])
VAR RollingWindow =
FILTER(
'Master Time Table',
'Master Time Table'[Date] <= MaxVisibleDate &&
'Master Time Table'[Date] > MaxVisibleDate - 10
)
RETURN
AVERAGEX(
RollingWindow,
COALESCE([Budget], 0)
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Thanks for the reply! Unfortunately that does not give me the correct values, I get the result (Forum) below: 

Jodallen123_1-1744012445354.png

 

 

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.