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
Anonymous
Not applicable

Slow DAX measure

So I have a dataset of 4.6million rows containing insurance rates for various quotes and their respective insurance company. I have managed to calculate a rank function that ranks each company's rates for each quote (KEY) and average it, keeping in mind filters made on the company name. It looks as follows:

 

Rank: AVERAGEX(VALUES('Test'[KEY]),RANKX( FILTER(ALLSELECTED('Test'[Company]),[AvgRate]),[AvgRate],,ASC))

AvgRate: AVERAGE('Test'[Rate])

 

However the rank measure takes really long to calculate to calculate. Looking into its timings in DAX Studio, it takes 39,161ms to run. Can anyone suggest an alternate way to structure my measure such that it takes less time?

2 REPLIES 2
v-eachen-msft
Community Support
Community Support

Hi @Anonymous ,

 

You could use VAR() to save the result of an expression as a named variable.

rank =
VAR a =
    VALUES ( 'Test'[KEY] )
VAR b =
    FILTER ( ALLSELECTED ( 'Test'[Company] ), [AvgRate] )
RETURN
    AVERAGEX ( a, RANKX ( b, [AvgRate],, ASC ) )

And you could refer to this video to learn how to optimize your dax.

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.
Anonymous
Not applicable

@v-eachen-msft Thanks for the suggestion however it took even longer in DAX Studio to as the total time to just calculate this measure was 63,723ms

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.