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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Suman8877
Advocate II
Advocate II

I need TOPN customer ?

Hi, 

There are slicers for Region, Country and, Reporting Unit in Power BI report and I need to show top 5 customers from TodaysTable data based on the selection made.

Table structure:
HistoryTable - with Region, Country, Reporting Unit, Revenue, & CombinationKey (REG + COUNTRY + RU)
TodaysTable - with Region, Country, Reporting Unit, Customer, Customer ID, Revenue & CombinationKey (REG + COUNTRY + RU)
MapTable - Active Relationship, Both directions on CombinationKey - DISTINCT(ALL(HistoryTable [CombinationKey], HistoryTable [Region], HistoryTable [RU], HistoryTable [Country]))

I created 2 Measures in TodaysTable

Todays Revenue = SUMX(TodaysTable , TodaysTable [Net Order Value])
Rank of Customer = RANKX(ALLSELECTED(TodaysTable [Customer]),[Todays Revenue],,DESC,DENSE)

and applied filter Rank of Customer <=5 in the report.

While this shows the result correctly when I have only Customer and Todays Revenue as columns in the table.

However, if I include Customer ID/ Region/ Country number of results shown just multiplies and I noticed that the Rank is repeating (multiple rows shows up as having Rank 1 while having different Revenues !!!) .

I m unable to understand this behavior.

It would be nice if someone could help me with correct DAX expression. that would enable me to show only 5 customers based on max revenue with additional fields (Region, Country, Customer ID).

Also, I would like to know if this can be achieved with a single DAX expression.

Thanks in advance. 

 

 

1 ACCEPTED SOLUTION
rohit1991
Super User
Super User

Hi @Suman8877 

The RANKX function works based on the field you are grouping by.

For example:

Rank of Customer =
RANKX(
  ALLSELECTED(TodaysTable[Customer]),
   [Todays Revenue],
   ,
   DESC,
   DENSE
)

 

This calculation ranks values at the Customer level.

 

  • If you want to rank by a combination key (such as Region + Country + RU), you need to replace Customer with that combination key.
  • If your report has separate columns for Region, Country, and RU, this approach can produce incorrect results.
  • The key principle is: the dimension you use in your visual should be the same dimension you use inside RANKX for accurate ranking.


Did it work? ✔ Give a Kudo • Mark as Solution – help others too!

View solution in original post

1 REPLY 1
rohit1991
Super User
Super User

Hi @Suman8877 

The RANKX function works based on the field you are grouping by.

For example:

Rank of Customer =
RANKX(
  ALLSELECTED(TodaysTable[Customer]),
   [Todays Revenue],
   ,
   DESC,
   DENSE
)

 

This calculation ranks values at the Customer level.

 

  • If you want to rank by a combination key (such as Region + Country + RU), you need to replace Customer with that combination key.
  • If your report has separate columns for Region, Country, and RU, this approach can produce incorrect results.
  • The key principle is: the dimension you use in your visual should be the same dimension you use inside RANKX for accurate ranking.


Did it work? ✔ Give a Kudo • Mark as Solution – help others too!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.