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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
lordmukund
Microsoft Employee
Microsoft Employee

Represent Top N values per Category based on a value using DAX or Power BI Desktop

How do we show top n values per category?

Say I want to show top 2 highest paid employees in each department as below then how can we do it in Power BI?

DepartmentEmployeeSalary
HRH19k
HRH28.9k
FinanceF110k
FinanceF29.7k
ITI110.5k
ITI210.3k

 

In SQL we can get this easily by using Dense_Rank function in CTE, but in power BI can someone please help me out?

2 REPLIES 2
amitchandak
Super User
Super User

@lordmukund , You can create a rank or topn column like

rank = RANKX(filter(allselected(table1,table1[Department],Table1[Employee]), Table1[Department] =max(Table1[Department])), sum(table1[Salary]),, desc)

 

In case Rank filter 2

 

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

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

Hi Amit i tried this but it is not working. 
I guess we need to use topn/groupby also along with this. but i am not sure how.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.