DAX RANKX function
Returns the rank of a value among a list of values.
RANKX ranks things by a measure: countries by sales, products by profit. Rank against ALL of the group, or every row ranks itself first.
Syntax
RANKX(<table>, <expression>[, <value>[, <order>[, <ties>]]])| Argument | Required | Description |
|---|---|---|
| table | Required | The list to rank among, usually ALL(column). |
| expression | Required | What to rank by, usually a measure. |
| value | Optional | The value to rank. Defaults to the expression in the current context. |
| order | Optional | DESC (default, largest is 1) or ASC. |
| ties | Optional | SKIP (default) or DENSE: how ranks continue after a tie. |
Returns: A whole number.
Examples
Calculated on the free practice data (table financials), with [Total Sales] = SUM(financials[Sales]) and [Total Profit] = SUM(financials[Profit]).
1. Country rank by sales
Country Rank = RANKX(ALL(financials[Country]), [Total Sales])| Country | Country Rank |
|---|---|
| Canada | 2 |
| France | 3 |
| Germany | 4 |
| Mexico | 5 |
| United States of America | 1 |
The United States sells the most, so it ranks 1.
Good to know
- Without ALL, each row sees only its own country and ranks 1.
- On a total row RANKX usually isn't meaningful: hide it with ISINSCOPE.
Related functions
Official reference: RANKX function on Microsoft Learn