DAX code
Rank Within Category =
-- ALLEXCEPT clears every filter on Product except Category, so ranking restarts per category
RANKX(
ALLEXCEPT('Product', 'Product'[Category]),
[Total Sales],
,
DESC,
DENSE
)
Ranks each product against only the other products in its own category, instead of the whole table.
Type your table and column names once. Every measure below updates.
Rank Within Category =
-- ALLEXCEPT clears every filter on Product except Category, so ranking restarts per category
RANKX(
ALLEXCEPT('Product', 'Product'[Category]),
[Total Sales],
,
DESC,
DENSE
)
Replace 'Product'[Category] with whatever column should define each ranking group.
Browse all 175 measures in the Power BI DAX Measures Library, or search the library for something similar to Rank Within Category.