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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
artjomsf
Frequent Visitor

Dynamically rank and group rows to show top-3 vs other

Hi all,

 

I have a table with data with sales per client per month, something simple like this:

artjomsf_0-1661350707507.png

Where I can achive ranking with RANKX.

 

Next I need: for each month to determine top-3 clients by "Amount" and compare see how much of total they do have, i.e. steps would be:

  • Rank clients
  • Sum top-3, sum all others
  • Get relative value in %

artjomsf_1-1661350811941.png

In the end Im looking for output like this:

artjomsf_2-1661350904530.png

 

So far I could do just RANKX ranking that does work with clients and months:

 ClientRank = RANKX (ALL(clients[Client]), calculate(sum(clients[amount])))

 but now I am struggling with having them aggregated in two groups. Is there a way to achieve that?

Thanks!

1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@artjomsf Create a disconnected table using an Enter Data query that contains 2 rows. Top 3 and Others

Construct a measure like:

 

Measure =
  VAR __Category = MAX('DisconnectedTable'[Value])
  VAR __Table = ADDCOLUMNS(SUMMARIZE('clients',[Client],[Month],"amount",[amount]),"rank",[ClientRank])
  VAR __Top3 = FILTER(__Table,[rank]<=3)
  VAR __Others = FILTER(__Table,[rank]>3)
  VAR __Amount = IF(__Category = "Top-3",SUMX(__Top3,[amount]),SUMX(__Others,[amount]))
RETURN
  __Amount

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
Greg_Deckler
Community Champion
Community Champion

@artjomsf Create a disconnected table using an Enter Data query that contains 2 rows. Top 3 and Others

Construct a measure like:

 

Measure =
  VAR __Category = MAX('DisconnectedTable'[Value])
  VAR __Table = ADDCOLUMNS(SUMMARIZE('clients',[Client],[Month],"amount",[amount]),"rank",[ClientRank])
  VAR __Top3 = FILTER(__Table,[rank]<=3)
  VAR __Others = FILTER(__Table,[rank]>3)
  VAR __Amount = IF(__Category = "Top-3",SUMX(__Top3,[amount]),SUMX(__Others,[amount]))
RETURN
  __Amount

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 

thanks a lot! That worked like charm! Just one more thing:

I have reworked that to match yearly instead of monthly data (which does not really matter), but I have calculation of total not right:

artjomsf_0-1661359119853.png

It shows Grand Total same as "Top-3" total. Could there be a solution to that?

 

@artjomsf Ah yes, Measure Totals. This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
amitchandak
Super User
Super User

@artjomsf , refer if this can help

https://www.proserveit.com/blog/ms-power-bi-topn-and-other

 

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

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

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

Top Solution Authors
Top Kudoed Authors