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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
738o51
Helper II
Helper II

Measure loads slowly

Hi Community,

 

I built a power bi that includes a measure for a rolling 5-day average. This rolling average can only include volume from non-weekends and non-holidays. I've gotten it to calculate correctly using the dax below, but it takes a while to run. Can anyone help me write this more efficiently?

 

Also, the business days index ranks business days in ascending order from today. In other words, the most recent business day is ranked 1 (today). The second most recent is ranked 2 (yesterday). Days in the date table that aren't business days are left blank.  

 

 

Rolling 5 day average_business days only = 

VAR TopRank = min(DateDim[Business days index])
Var RankUL = TopRank+5
VAR RollingSum = 
    sumx(
        filter(
            ALLSELECTED('Visit Details'),
                'Visit Details'[Business day index] < RankUL &&
                'Visit Details'[Business day index] >= TopRank),
        [Total Visits])    
Return Divide(RollingSum,5)

 

 

Thank you in advance for your help!

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@738o51 Maybe try:

Rolling 5 day average_business days only = 
VAR TopRank = min(DateDim[Business days index])
Var RankUL = TopRank+5
VAR RollingSum = 
    CALCULATE
        SUM([Total Visits]),
        filter(
            ALLSELECTED('Visit Details'),
                'Visit Details'[Business day index] < RankUL &&
                'Visit Details'[Business day index] >= TopRank),
    )  
Return Divide(RollingSum,5)

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

@738o51 Maybe try:

Rolling 5 day average_business days only = 
VAR TopRank = min(DateDim[Business days index])
Var RankUL = TopRank+5
VAR RollingSum = 
    CALCULATE
        SUM([Total Visits]),
        filter(
            ALLSELECTED('Visit Details'),
                'Visit Details'[Business day index] < RankUL &&
                'Visit Details'[Business day index] >= TopRank),
    )  
Return Divide(RollingSum,5)

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler  Thank you!!

@738o51 - Curious, how much did that speed things up?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

My data set is pretty large so the change was significant. I went from about 2 minutes to load the graph to about 1 second. Thanks again!

@Greg_Deckler 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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