The RANKX function in DAX is used to rank values in a table based on a measure or column. It is commonly used to find the top-performing products, salespeople, regions, or any other ranked metric in your dataset.
RANKX works with a table and evaluates a expression for each row to determine the rank.
Syntax
RANKX(<table>, <expression>, [<value>], [<order>], [<ties>])
- table โ The table containing values to rank
- expression โ The value or measure to rank
- value โ Optional. Specific value to rank (usually left blank)
- order โ ASC (ascending) or DESC (descending). Default is descending
- ties โ Optional. Determines ranking method for ties: SKIP (default) or DENSE
Example 1 โ Rank Products by Sales
Product Rank =
RANKX(
ALL(Products[ProductName]),
SUM(Sales[Amount]),
,
DESC,
SKIP
)
- This measure ranks products based on total sales.
- ALL(Products[ProductName]) removes filters so the ranking is across all products.
- DESC ranks highest sales as 1.
Example 2 โ Rank Regions by Profit
Region Rank =
RANKX(
ALL(Sales[Region]),
SUM(Sales[Profit]),
,
DESC,
DENSE
)
- This measure ranks regions based on total profit.
- DENSE ensures consecutive ranks even if there are ties.
Tips for Using RANKX
- Always consider using ALL or ALLSELECTED to control the filter context for ranking
- Use DENSE ranking when you want no gaps in rank numbers
- Combine with Top N filters to display top performers in visuals
- Rank measures are dynamic and respond to slicers and filters
Conclusion
RANKX is a powerful DAX function for ranking data dynamically in Power BI. It is essential for identifying top performers, benchmarking, and creating interactive dashboards with ranking insights.