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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Show Top Product per Category Based on Sales

Hi Community,

 

I'm having trouble with a DAX formula showing the top product in a category. I have a data model with a sales table and a product table. In the report view I would like to make a table containing the category name, sum of total sales for this category, the top selling product within the category. I only need one product per category. The resulting table should look like this:

 

Product CategorySum of SalesTop Product Based on Sales
Fruit10000Banana
vegetables9000Carrot
Bread8000White Casino

 

I've looked around but couldnt find a article explaining the formula I need. If anybody has any suggestions or knows a related article that would be very helpfull.

 

Thanks in advance!

 

1 ACCEPTED SOLUTION
az38
Community Champion
Community Champion

Hi @Anonymous 

what rule should be applied for a tie-situation when two or more products have the same top sales within category?

anyway, you could add a calculated column

Rank = RANKX(FILTER(ALL('Table');'Table'[Product Category]=EARLIER('Table'[Product Category]));'Table'[Sales])

then create a measure

Top Product Based on Sales = calculate(FIRSTNONBLANK('Table'[Product];1);ALLEXCEPT('Table';'Table'[Product Category]);'Table'[Rank]=1)

add this measure to visual and set aggregation as Sum for field [Sales] in visual fields settings

 

do not hesitate to give a kudo to useful posts and mark solutions as solution

LinkedIn


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

1 REPLY 1
az38
Community Champion
Community Champion

Hi @Anonymous 

what rule should be applied for a tie-situation when two or more products have the same top sales within category?

anyway, you could add a calculated column

Rank = RANKX(FILTER(ALL('Table');'Table'[Product Category]=EARLIER('Table'[Product Category]));'Table'[Sales])

then create a measure

Top Product Based on Sales = calculate(FIRSTNONBLANK('Table'[Product];1);ALLEXCEPT('Table';'Table'[Product Category]);'Table'[Rank]=1)

add this measure to visual and set aggregation as Sum for field [Sales] in visual fields settings

 

do not hesitate to give a kudo to useful posts and mark solutions as solution

LinkedIn


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.