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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
brettmacdonald8
New Member

Moving Averages - Relative Data Slicer

Hello - I am trying to use a DAX function to calculate the rolling average of Google Analytics sessions with a custom date range. I use the following function:

 

Rolling Average Sessions =
 AVERAGEX(
        FILTER( ALLSELECTED('Date Functions'[Date]),
                 'Date Functions'[Date] <= MAX('Date Functions'[Date])),
                           'Date Functions'[Sessions])
 
I assume the issue has something to do with having several instances of the same date because I believe these are hourly session totals. Any help would be much appreciated 
 
 

Screenshot 2020-12-12 220159.png

3 REPLIES 3
amitchandak
Super User
Super User

@brettmacdonald8 , Seems like you are creating like a column. For new column try like

Rolling Average Sessions =
AVERAGEX(
FILTER( 'Date Functions',
'Date Functions'[Date] <= earlier('Date Functions'[Date])),
'Date Functions'[Sessions])

 

For new measure

 

Rolling Average Sessions =
AVERAGEX(
FILTER( ALLSELECTED('Date Functions'),
'Date Functions'[Date] <= MAX('Date Functions'[Date])),
'Date Functions'[Sessions])

 

or better to use a separate date table

 

Rolling Average Sessions =
AVERAGEX(
FILTER( ALLSELECTED('Date Functions'),
'Date Functions'[Date] <= MAX('Date Functions'[Date])),
'Date Functions'[Sessions])

 

Rolling Average Sessions =
AVERAGEX(
FILTER( ALLSELECTED('Date'),
'Date'[Date] <= MAX('Date'[Date])),
'Date Functions'[Sessions])

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
CNENFRNL
Community Champion
Community Champion

Hi, @brettmacdonald8 , you might want to try this formula in a calculated column

 

Rolling Average Sessions =
AVERAGEX (
    FILTER (
        ALL ( 'Date Functions'[Date] ),
        'Date Functions'[Date] <= EARLIER ( 'Date Functions'[Date] )
    ),
    'Date Functions'[Sessions]
)

 

 


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

daxer-almighty
Solution Sage
Solution Sage

I'd strongly and kindly suggest you read about ALLSELECTED. You're not using it properly and don't understand what it's for and how it behaves. Here's an article: The definitive guide to ALLSELECTED - SQLBI

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.