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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.

Top Solution Authors