Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
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?
| Department | Employee | Salary |
| HR | H1 | 9k |
| HR | H2 | 8.9k |
| Finance | F1 | 10k |
| Finance | F2 | 9.7k |
| IT | I1 | 10.5k |
| IT | I2 | 10.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?
@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...
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.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.
| User | Count |
|---|---|
| 8 | |
| 7 | |
| 6 | |
| 5 | |
| 5 |
| User | Count |
|---|---|
| 24 | |
| 11 | |
| 9 | |
| 9 | |
| 8 |