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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Giorgi1989
Advocate II
Advocate II

Issues with RANKX and TOPN

Dear All,

 

What I am trying to achieve is to rank top 10 customers by Gross Margin % (which is a calculated measure). I have two DAX formula as follows:

 

Customer rank based on GM% =
Calculate(
RANKX(
ALLSELECTED('Customer (Margin)'[Customer]),
[Gross Margin %],,DESC),
FILTER('Customer (Margin)', 'Customer (Margin)'[Gross Margin %] <> BLANK () )
)
 
 
Top 10 customers by GM% =
IF(
NOT(ISBLANK([Gross Margin %])),
MAXX(
TOPN(
10, SUMMARIZE('Customer (Margin)','Customer (Margin)'[Customer],'Customer (Margin)'[GM%])),'Customer (Margin)'[Gross Margin %]))
 
When I throw in these measures in the Matrix, what I get is this:
 
Giorgi1989_0-1648810250353.png

Any ideas where I am making an error? 

 

My expected output is:

 

Customer A - Gross Margin % 65% - Rank 1

Customer B - Gross Margin % 65% - Rank 2

etc.

 

Any help appreciated.


Thank you!

1 ACCEPTED SOLUTION

Thank you for your suggestions and time. In the end, I decided to have an entirely different approach to creating a page with margin information, top and bottom performers, both customers and products. 

View solution in original post

4 REPLIES 4
tamerj1
Super User
Super User

Hi @Giorgi1989 
Can you please advise what are you slicing by in your matrix? Why are you taking the MAXX of the TOPN(10)? As this is just the same as simple MAXX

Hi, 

 

Thank you for the quick reply. 

 

I use 'calendar month' to slice the matrix. 

@Giorgi1989 
You may try the following 

Customer rank based on GM% =
RANKX (
    FILTER ( 'Customer (Margin)', 'Customer (Margin)'[Gross Margin %] <> BLANK () ),
    [Gross Margin %],
    ,
    DESC
)
Top 10 customers by GM% =
IF (
    NOT ( ISBLANK ( [Gross Margin %] ) ),
    MAXX (
        ADDCOLUMNS ( 'Customer (Margin)', "@GrossMagin", [Gross Margin %] ),
        [@GrossMagin]
    )
)

Thank you for your suggestions and time. In the end, I decided to have an entirely different approach to creating a page with margin information, top and bottom performers, both customers and products. 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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