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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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