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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
PunchBird
Helper V
Helper V

DAX measure to calculate weekly rolling average not working

Hi,

 

I am trying to create a DAX measure that calculates the weekly rolling average but it's not working.

 

The measure is:

weekly rolav = 
VAR ValueToday = CALCULATE(SUM('Sales'[Total]), LASTDATE('Date'[Date]))
VAR WeekRol =
CALCULATE(
    AVERAGEX( VALUES( 'Date'[Date]), ValueToday),
    DATESINPERIOD( 'Date'[Date], MAX( 'Date'[Date] ), -7, DAY )
)
RETURN
WeekRol
 

And this is the result I get, it's basically calculating the sum instead of weekly rolling average:

PunchBird_0-1681573356213.png

Can anyone indicate what I am doing wrong here?

Thanks!

@parry2k @amitchandak @lbendlin 

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@PunchBird I think this is what you are looking for

 

Weekly Rolling Avg = 
AVERAGEX (
    DATESINPERIOD ( 'Calendar'[Date], MAX ( 'Calendar'[Date] ), -7, DAY ),
    CALCULATE ( SUM ( 'Sales'[Total] ) )
)


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

5 REPLIES 5
parry2k
Super User
Super User

@PunchBird to confirm, on the 3rd of April, the average will go back to the 2nd and 3rd of April, not going to the last month, in other words not prior to the 2nd of April? Correct?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k   my previous question was a bit confusing, my apologies. What I actually needed (next to the rolling average) is to compare the average of a selected period (e.g. last 7 days) with the same period previous, so the average of 9-16 April compared to the average of 1-8 April. I created the following DAX measures: 

Average This Period =

VAR dayCount = COUNT('Date'[Date])

VAR startDate = MAX ( 'Date'[Date] ) - ((1 * dayCount) - 1)

VAR endDate = MAX ( 'Date'[Date] )

VAR thisPeriod = CALCULATE( SUM('A1'[Total]), DATESBETWEEN( 'Date'[Date], startDate, endDate) )

RETURN

DIVIDE(thisPeriod,dayCount,0) 

 

Average Previous Period =

VAR dayCount = COUNT('Date'[Date])

VAR startDate = MAX ( 'Date'[Date] ) - ((2 * dayCount) - 1)

VAR endDate = MAX ( 'Date'[Date] ) - (1 * dayCount)

VAR previousPeriod = CALCULATE( SUM('A1'[Total]), DATESBETWEEN( 'Date'[Date], startDate, endDate) )

RETURN

DIVIDE(previousPeriod,dayCount,0)

 

These measures seem to work when I put the measures each in a Card visual (I checked in Excel and the values are calculated correctly):

PunchBird_2-1681638209302.png

The only problem now is when I put these measures in a KPI visual ('this period' in Value and 'previous period' in Target), it displays the value of today and yesterday.... Any idea what's happening here? 

 

 

 

PunchBird_3-1681638258034.png

 

@parry2k

parry2k
Super User
Super User

@PunchBird I think this is what you are looking for

 

Weekly Rolling Avg = 
AVERAGEX (
    DATESINPERIOD ( 'Calendar'[Date], MAX ( 'Calendar'[Date] ), -7, DAY ),
    CALCULATE ( SUM ( 'Sales'[Total] ) )
)


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k one more question - how do I now create a measure that calculates the average of this weekly rolling average for the date period selected? So in the example below, when a date range is selected I would like to calculate the average of the weekly rolling average values of the selected date range.

PunchBird_1-1681590866447.png

 

 

That's what I was looking for indeed, many thanks!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors