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
Ajinkya369
Resolver III
Resolver III

Top 5 and Bottom 5 Products within each categories

Hi folks,

Data structure: 

Category A: Product1,Product2,Product3.....so on

Category B: Product1,Product2,Product3.....so on

I want to calculate Top 5 and Bottom 5 products within each category.For Top 5 Products within each category I have used this formula:

Top 5 Products within each category =
VAR RankingContext = VALUES(‘Dim Products’[Products])
return
CALCULATE([Sum of sales],TOPN(5,ALL(‘Dim Products’[Products]),[Sum of sales]),RankingContext)

I am using Category and Product(Drill down) in rows section of Matrix and the Measure " Top 5 Products within each category" in the values section.
Its working well for Top 5 but I need help in calculating the bottom 5 products within each category.

Thanks in advance.

3 REPLIES 3
Anonymous
Not applicable

Hi @Ajinkya369,
Can please share some dummy data with a similar data structure and expected results? It should help us clarify your scenario and test to coding formula.
How to Get Your Question Answered Quickly 
Regards,
Xiaoxin Sheng

Ajinkya369
Resolver III
Resolver III

Hey @amitchandak ,

 

Thanks for the reply! It is for Top N products within each category whereas I am looking for Bottom N Products within each category.

 

Thanks,

Ajinkya

amitchandak
Super User
Super User

@Ajinkya369 , refer if this can help

https://www.sqlbi.com/articles/filtering-the-top-3-products-for-each-category-in-power-bi/

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
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.