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>]]])
ArgumentRequiredDescription
tableRequiredThe list to rank among, usually ALL(column).
expressionRequiredWhat to rank by, usually a measure.
valueOptionalThe value to rank. Defaults to the expression in the current context.
orderOptionalDESC (default, largest is 1) or ASC.
tiesOptionalSKIP (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])
CountryCountry Rank
Canada2
France3
Germany4
Mexico5
United States of America1

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