DAX RANKX Function

Dynamic ranking of customers, products, and categories.

Syntax
RANKX( Table, Expression, [Value], [Order], [Ties] )

Overview

RANKX computes the rank of an expression across a given table or set of dimension keys in the current visual context.

To rank correctly in Power BI, you must supply an unfiltered table (typically wrapped in ALL) as argument 1, and the measure to rank by as argument 2. This ensures the current row coordinate can be evaluated against the entire population.

Customer Revenue Rank = 
RANKX(
    ALL(Customers),
    [Total Revenue],
    ,
    DESC,
    Dense
)

When to use RANKX

  • Ranking items (customers, products, stores) by a measure in the current filter context.
  • Top-N style labels and conditional formatting based on rank.
  • Ranking within a group, such as products within each category.

Worked examples

Rank customers by sales

Customer Rank =
RANKX ( ALL ( Customer[Customer] ), [Total Sales], , DESC, DENSE )

ALL makes the ranking compare each customer with all customers rather than only the one on the current row (which would always rank 1). DENSE avoids gaps after ties.

Rank within the user's selection

Customer Rank (Selected) =
RANKX ( ALLSELECTED ( Customer[Customer] ), [Total Sales], , DESC )

ALLSELECTED ranks among the customers the user has filtered to with slicers, so the top item in the current view is rank 1.

Common mistakes

  • Passing Customers without ALL()—the measure will evaluate only the single filtered customer and return 1 for everybody!
  • Forgetting to handle ties (Skip vs Dense ranking).

Performance notes

RANKX evaluates the measure once per item in the ranking table, so cost grows with the number of items and the cost of the measure. Ranking a few thousand customers is fine; ranking millions of transactions is not. Newer window functions such as RANK can also be considered for complex ranking scenarios.

Frequently asked questions

Why does RANKX return 1 for every row?
The table argument is filtered to the current row, so each item is ranked against itself. Use ALL or ALLSELECTED on the column being ranked.
How do I handle ties in RANKX?
Use the fifth argument: SKIP (the default) leaves gaps after ties, DENSE does not.
Why does the total row show a rank?
On the total row RANKX still evaluates. Hide it with IF(ISINSCOPE(Customer[Customer]), RANKX(...)).

Related DAX concepts