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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Sergii24
Super User
Super User

DAX Performance Issue - 7 days moving average over 100 years of data

Hi all,

 

In my dataset there are 2 tables: fact table "Fact" (31k rows) and "DateTable" (marked as date table and has 46K rows). I have data on daily level starting from 1896 until 2021. My objective is to calculate 7 days moving average of column "Close", considering that there are empty spaces in the "Fact table" (dates in this table are not consecutive).

 

However, I have difficulties way earlier I get to this calculation. When I write one of the simpliest DAX expression such as the one below, it takes minutes to compute it and sometimes I get an error saying that there is no enough memory to compute it!

 

 

Test = 
VAR TestDate = MIN( DateTable[Date] )
RETURN
    CALCULATE(
        AVERAGE( Fact[close] ),
        DateTable[Date] < TestDate
    )

 

 

What am I doing wrong? I don't belive that Power BI has difficulties in such calculation over 30k rows. Am I wrong?
Link to the file is here.


Thanks!

1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

 

7 DAYS MA =
CALCULATE (
    AVERAGE ( 'Fact'[close] ),
    DATESINPERIOD ( DateTable[Date], MAX ( DateTable[Date] ), -7, DAY )
)

 


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!

View solution in original post

1 REPLY 1
CNENFRNL
Community Champion
Community Champion

 

7 DAYS MA =
CALCULATE (
    AVERAGE ( 'Fact'[close] ),
    DATESINPERIOD ( DateTable[Date], MAX ( DateTable[Date] ), -7, DAY )
)

 


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!

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.