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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
danm
Helper I
Helper I

Top 10 - DAX formula optimization

Hi Experts, 

 

I try to create a measure to create Top 1o Customer by number of products bought.
I use the following formulas:

 

Customer Rank = RANKX(ALL(Sales_Fact[CustomerNumber]), [Total Sales], ,ASC)

 

Top 10 Customers by Prod # =
VAR
RankingContext = VALUES( Account_Dim[Name] )
RETURN
CALCULATE( [No of unique Products],
TOPN( 10, ALL( Account_Dim[Name] ), [No of unique Products] ),
RankingContext ).

 

The problem is taking around 5 min to display a table with 10 CustomerName and Rank. The tables are not huge: Account aprox 90.ooo rows and Sales aprox 120.000.  The memory and cpu used around 30-40%.

 

Any help would be very much appreciated!

 

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

Hi @danm 

I'd need more details on the model, visual where measures are used etc. Can you share the pbix?

The name for the measure [Top 10 Customers by Prod #] is a bit confusing, given what it seems to do.

Try this in the meantime:

Top 10 Customers by Prod # V2 =
VAR rank_ =
    RANKX ( ALL ( Account_Dim[Name] ), [No of unique Products] )
RETURN
    IF ( rank_ <= 10, [No of unique Products] )

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

View solution in original post

7 REPLIES 7
AlB
Community Champion
Community Champion

@danm 

Essentially it is doing what you did in a more direct way.  Your code was a bit convoluted.

To be quite honest though, I wouldn't expect the improvement to be really big ex ante. I'd need to see the full pbix to be able to provide a more accurate answer.

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

 

 

danm
Helper I
Helper I

Thank you @AlB !

Is simple and fast ! Great solution. We all appreciate if you add some comments to point us in right direction.

 

Cheers

AlB
Community Champion
Community Champion

Hi @danm 

I'd need more details on the model, visual where measures are used etc. Can you share the pbix?

The name for the measure [Top 10 Customers by Prod #] is a bit confusing, given what it seems to do.

Try this in the meantime:

Top 10 Customers by Prod # V2 =
VAR rank_ =
    RANKX ( ALL ( Account_Dim[Name] ), [No of unique Products] )
RETURN
    IF ( rank_ <= 10, [No of unique Products] )

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

amitchandak
Super User
Super User

@danm , In the model view, check relations and try to convert  1-M relation as single direction relation

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
danm
Helper I
Helper I

Hi @

 

Not sure about the slicer

amitchandak
Super User
Super User

@danm , do you have any bi-directional joins. and having a slicer for those bi-directional joins. Make bi-directional join and try .

Small variation in second formula

 

No of unique Products = DISTINCTCOUNT(Sales_Fact[ProductNumber])

Top 10 Customers by Prod # =
CALCULATE( [No of unique Products],
TOPN( 10, ALL( Account_Dim[Name] ), [No of unique Products] ),
VALUES( Account_Dim[Name] ) )

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
danm
Helper I
Helper I

No of unique Products = DISTINCTCOUNT(Sales_Fact[ProductNumber])

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.