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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
kucci
Frequent Visitor

Efficient way to calculate top % within a category

Hi, I've got a huge data set of >1.5mil rows loaded in Power BI. I'm trying to segmentise the top 2%, next 20%, remaining 78% by value within each category (A, B, C). I've been adding columns using M instead of DAX as I read that the performance is faster since the data set is quite big. I was exploring creating tables based on top N values but that might be quite tedious; also sorting from high to low and assigning % might be an option too but it'll be too taxing on the performance. Any suggestions on efficient ways to do it?

 

Thank you!

 

Resulting table should add the 4th column with tagging

PersonCategoryValueTagging
Person 1A100Top 2%
Person 2A80Next 20%
Person 3A60Remaining 70%
Person 4A40Remaining 70%
Person 5A20Remaining 70%
Person 6A10Remaining 70%
Person 7B200...
Person 8C50...
Person 9C50...

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @kucci 

You may try to build calculated columns, and it works well.

I build a sample which has 1 million rows to have a test.

Rank = RANKX(FILTER(Sheet2,Sheet2[Category]=EARLIER(Sheet2[Category])),Sheet2[Value],,DESC,Dense)
Tag = 
Var  _MaxRank = MAXX(FILTER(Sheet2,Sheet2[Category] = EARLIER(Sheet2[Category])),Sheet2[Rank])
return
SWITCH(TRUE(),Sheet2[Rank]<=_MaxRank*0.02,"	Top 2%",Sheet2[Rank]<=_MaxRank*0.22,"Next 20%","Remaining 70%")

Result:

1.png

If this reply still could't help you solve your problem, could you tell me your calculate logic to calculate TopN?

Did you calcualte the Top N by the rank for each category?

 

You can download the pbix file from this link: Efficient way to calculate top % within a category

 

Best Regards,

Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @kucci 

You may try to build calculated columns, and it works well.

I build a sample which has 1 million rows to have a test.

Rank = RANKX(FILTER(Sheet2,Sheet2[Category]=EARLIER(Sheet2[Category])),Sheet2[Value],,DESC,Dense)
Tag = 
Var  _MaxRank = MAXX(FILTER(Sheet2,Sheet2[Category] = EARLIER(Sheet2[Category])),Sheet2[Rank])
return
SWITCH(TRUE(),Sheet2[Rank]<=_MaxRank*0.02,"	Top 2%",Sheet2[Rank]<=_MaxRank*0.22,"Next 20%","Remaining 70%")

Result:

1.png

If this reply still could't help you solve your problem, could you tell me your calculate logic to calculate TopN?

Did you calcualte the Top N by the rank for each category?

 

You can download the pbix file from this link: Efficient way to calculate top % within a category

 

Best Regards,

Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

 

Thanks, this worked well! I didn't realise that I had to create a calculated column instead of a measure.

amitchandak
Super User
Super User

@kucci , see if this percentile blog can help 

https://blog.enterprisedna.co/implementing-80-20-logic-in-your-power-bi-analysis/
https://forum.enterprisedna.co/t/testing-the-pareto-principle-80-20-rule-in-power-bi-w-dax/459
https://finance-bi.com/power-bi-pareto-analysis/
https://community.powerbi.com/t5/DAX-Commands-and-Tips/Calculate-the-sum-of-the-top-80/td-p/763156

 

I think there is a blog from Greg on cumulative bucketing. I do not have the link handy.

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
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