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

Creating a Top N and Others Table from related table (using Rankx)

Hello,

 

I'm trying to create a table showing say Top 5 Sales by Products and the balance in others. My tables are as follows:

 

SalesTable  
CustomerProductAmount
AAAA100
BBBB50
CCCC10
DAAA100

 

ProductsTable 
ProductDescription
AAA 
BBB 
CCC 

 

Intended output...

Ranked Product Table 
ProductSales
AAA200
BBB50
Others10



I have tried the solution here, but came across errors.
I am able to rank the products with the following formula:
Product Rank = RANKX(ALL('ProductsTable'[product]),SUMX(RELATEDTABLE('SalesTable'),'SalesTable'[Amount]))

I am unable to create the next formula:
Top 5 products = IF([Product Rank]<6,'ProductsTable'[product],"others") where i am unable to reference the column, 'ProductsTable'[product], either directly or using RELATED.

Does anyone know how to solve this?

2 REPLIES 2
amitchandak
Super User
Super User

@Anonymous , try like

rank1 =RANKX(ALL('ProductsTable'[product]),calculate(SUM('SalesTable'[Amount])))

calculate(sum('SalesTable'[Amount]),filter('SalesTable',[rank1]<=5))

 

For Rank Refer these links
https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns
https://radacad.com/how-to-use-rankx-in-dax-part-3-of-3-the-finale
https://community.powerbi.com/t5/Community-Blog/Dynamic-TopN-made-easy-with-What-If-Parameter/ba-p/367415

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
harshnathani
Community Champion
Community Champion

Hi @Anonymous ,

 

You can have a look at the blog.

 

https://blog.gbrueckl.at/2019/05/power-bi-dynamic-topn-others-with-drill-down/

 

https://www.youtube.com/watch?v=UAnylK9bm1I

 

 

Regards,

Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

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.

Top Solution Authors