Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
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 Category | Sum of Sales | Top Product Based on Sales |
Fruit | 10000 | Banana |
vegetables | 9000 | Carrot |
Bread | 8000 | White 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!
Solved! Go to Solution.
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
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
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
11 | |
11 | |
10 | |
9 | |
8 |
User | Count |
---|---|
17 | |
12 | |
11 | |
11 | |
11 |