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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
nbs33
Helper II
Helper II

Optimize DAX 12 MM Meausre

Hi,

 

I have been struggling with this issue for a while. I am a fact table of about 2.5 million rows and multiple dimension tables, the largest being a cusotmer table of about 165,000 rows. I also have a date table.

 

I was able to analyze the query and find that the majority of the time was takening up joining the Cusotmer Dim to the Date Dim. ( 165,000 cusotmer x 365 days ( see query below) = aprox. 58 million records).

 

Orginal Measure:

 

 

Original Revenue 12MM = 
VAR revenue12mm = CALCULATE( SUM( Fact[Revenue] ),
        REMOVEFILTERS(Dates[Date]),
         DATESINPERIOD(Dates[Date], LASTDATE(Invoice[ReportingDate]), -12, MONTH)
     )

RETURN 

revenue12mm

 

 

 

I was about to reduce the cardinality in my fact table by reducing he the reporting date to a monthly value ( mm/01/yyyy) and found better performance by not using the DATESINPERIOD.

 

 

Optimized Revenue 12MM = 
VAR MaxDate = CALCULATE( SELECTEDVALUE( Dates[Month Year] ), Dates[Date] =  MAX(Fact[ReportingDate]) )
VAR MinDate =  DATE( YEAR( MaxDate )-1 , MONTH( MaxDate ) +1, 1)
VAR revenue12mm = 
CALCULATE( SUM( Fact[Revenue]),
        Fact[ReportingDate] <= MaxDate &&
        Fact[ReportingDate] >= MinDate
    )
RETURN
revenue12mm

 

 


This optimized query runs in about 16 seconds but it is still painfully slow. It seems like the majority of time still spent with the join on Customer and Date. It is down to 1.4 million rows.

 

Any ideas how to improve this?

 

6 REPLIES 6
djurecicK2
Super User
Super User

Hi @nbs33 ,

 Can I ask why you are trying to filter on MAX(Fact[ReportingDate]?

 

If you are looking for YTD, could you just use TOTALYTD function?

Hi @djurecicK2 thank you for your input.  I am not sure what you are refereing to. The the YTD functions work well.  The two 12MM measurse are the slow ones. Are you refering to these measures?

nbs33
Helper II
Helper II

@daXtreme & @amitchandak I apprciate both of your inputs. 

 

I have created a stripped down dataset so you can see issue first hand. ( pbix File )

 

The performance is improved in the sample after removing the majority of columns but the main issue still presists. 

 

From what I can tell if specific to them Revenue 12MM and Premium 12 MM measures. 

 

I am only in the begining of my learnings about DAX optimization so you insights are greatly appreciated. 

v-shex-msft
Community Support
Community Support

Hi @nbs33,

Did the above suggestions help with your scenario? if that is the case, you can consider Kudo or Accept the helpful suggestions to help others who faced similar requirements.

If these also don't help, please share more detailed information to help us clarify your scenario to test.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
daXtreme
Solution Sage
Solution Sage

It's literally not possible to optimize code without having the model and data in front of the eyes. Supply some data to play with (representative!) and then we can talk. Also, the hardware plays a role in how fast your DAX is gonna work on big models.

amitchandak
Super User
Super User

@nbs33 , the second one seems better, You can mark the join column as key column

 

try this one

 

rolling 12 =
var _max = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
var _min = date(Year(_max), month(_max) -12, Day(_max))+1
BLANK())
return
CALCULATE(SUM( Fact[Revenue]) ,DATESBETWEEN('Date'[Date],_min,_max))

 

Original Revenue 12MM =
CALCULATE( SUM( Fact[Revenue] ),
DATESINPERIOD(Dates[Date], LASTDATE(Invoice[ReportingDate]), -12, MONTH)
)


Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

July Newsletter

Fabric Community Update - July 2024

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

Top Solution Authors
Top Kudoed Authors