# Top 5 and Bottom 5 Product within categories

Hi folks,

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.

Hi @ajinkyakadam0009, we aim to consistently improve the topics being posted on the forum to help you in getting a strong solution faster. While waiting for a response, here are some tips so you can get the most out of the forum and other Enterprise DNA resources.

• Use the forum search to discover if your query has been asked before by another member.
• When posting a topic with formula make sure that it is correctly formatted to preformatted text </>.
• Use the proper category that best describes your topic
• Provide as much context to a question as possible.
• Include the masked demo pbix file, images of the entire scenario you are dealing with, screenshot of the data model, details of how you want to visualize a result, and any other supporting links and details.

I also suggest that you check the forum guideline How To Use The Enterprise DNA Support Forum. Not adhering to it may sometimes cause delay in getting an answer.

Hi

Not that I am an expert like @MudassirAli or @AntrikshSharma or @EnterpriseDNA,

but if I may be humble and say this that try

multiplication of multiple ranking functions
such as

RANKX(ALL(your data), [Explicit measure], , ASC) *
RANKX(ALL(your data), [Explicit measure], , DESC)

Thanks

1 Like

Just replacee DESC with ASC for Bottom products.

``````Top 5 Products within each category =
CALCULATE (
[Sum of sales],
KEEPFILTERS (
TOPN ( 5, ALL ( 'Dim Products'[Products] ), [Sum of sales], DESC )
)
)``````
1 Like

Never be hesitant to offer an alternative solution on this forum. The best threads offer multiple solutions to the same problem.

I’m not sure why @ajinkyakadam0009 posted the same question in two separate threads, but in the other thread I offered probably an unnecessarily complex solution. However, I tried your measure within the solution file I provided, and I’m not seeing how it solves the problem. If you could please elaborate, that would be great.

Thanks!

• Brian