Ravindra BagaleCourses & study guides Track your progress

Guides

RANKX in Power BI DAX — Rank Cities and Products

RANKX returns the rank of the current item among a table of competitors evaluated by an expression — usually a measure like [Total Sales] — and filter context decides who is on the leaderboard.

Chala mitrano! Leaderboards make sense to every stakeholder. Why? “Top city” is clearer than a raw table of twenty numbers. How? We write a beginner RANKX on FreshBasket (fictional) cities, talk ties, and peek at ALL vs ALLSELECTED. Competitive, but calm.

Quick answer

Vertical ranking:

  1. Solid [Total Sales] first.
  2. City Rank = RANKX ( ALL ( Customer[City] ), [Total Sales], , DESC ).
  3. Table visual: City + Total Sales + City Rank.
  4. Rank 1 should be the highest sales city.
  5. Decide how ties should look (skip vs dense) when you need precision.
  6. Change ALL vs ALLSELECTED intentionally — do not guess.
RANKX ( ALL ( Customer[City] ), [Total Sales], , DESC )

Why RANKX, rows in / number out

City Total Sales
Mumbai 140
Nashik 80
Pune 60
  1. Why RANKX: managers want position, not only rupees.
  2. Competitors table = all cities (via ALL ( Customer[City] )).
  3. Expression = [Total Sales].
  4. DESC → biggest first. Mumbai 140 → rank 1. Nashik 80 → 2. Pune 60 → 3.
  5. Number out is a rank integer, not the sales amount.
  6. If two cities both had 140, ties share logic — say the rule aloud before arguing.
RANKX basics RANKX ranks the current item among a table of competitors by an expression. Table of itemsCities / Products RANKX 1, 2, 3… rank

RANKX ranks the current item among a table of competitors using an expression (often a measure).

What do I need before this guide?

Before and after (look at the tables first)

Before RANKX City sales without ranks.

Before

After RANKX Mumbai rank 1, Nashik 2, Pune 3.

After

RANKX shape

City Rank =
RANKX (
    ALL ( Customer[City] ),
    [Total Sales],
    ,
    DESC
)
  1. Table argument = who competes (all cities here).
  2. Expression = what we rank by.
  3. DESC → biggest sales gets rank 1.
  4. Adjust table/column names to your model.

Shop analogy: RANKX is the race result sheet. Sales is the finish time (higher is better with DESC). ALL is “everyone races,” not only the one city on the row.

Ties

RANKX ties Dense vs skip ties: decide how equal sales share rank numbers. Ties: 1, 2, 2, 4skip (default-ish) Dense: 1, 2, 2, 3no gap ties

Ties matter: skip vs dense ranking changes how equal values share places — say which you want.

  1. Equal sales can share ranks.
  2. Some patterns skip numbers after ties; dense ranking does not.
  3. Say the rule aloud before debating “wrong” ranks.

Filter context and scope

RANKX and filter context What you rank against depends on ALL / ALLSELECTED / filters. Visible rows RANKX vs ALL? scope

Who you rank against depends on filter context — ALL / ALLSELECTED / visible rows change the leaderboard.

  1. ALL ( City ) makes every city compete even if the row is filtered.
  2. ALLSELECTED variants rank inside what the user currently selected.
  3. Wrong scope = “why is everything rank 1?”

Mistakes and calm fixes

Symptom Likely cause Fix
All rank 1 Competitors table too small Use ALL / wider table
Rank ignores slicer wrongly ALL vs ALLSELECTED mismatch Match business question
Blank ranks Expression blank Fix base measure
Card shows one number only No competitor context Use table/matrix by City

Ghabru naka 😅 — RANKX without a competitor table is like a race with one runner.

Ravindra Bagale's Tip

Interview line that scores: “RANKX needs a table of competitors and an expression; ALL controls whether ranks ignore the City filter on the row.” Then give one example. Got it?

Practice task

  1. Build City Rank with ALL ( City ).
  2. Sort the table by rank (Mumbai should be 1 when it has 140).
  3. Add a Region slicer; try an ALLSELECTED variant.
  4. Find a tie (or create equal sample sales) and note ranks.
  5. Write which scope your manager wants.

Learn it properly

Course lessons:

Related guides: % of total ALLSELECTED · ALL family

Got it? RANKX ranks among a table; scope is everything. Next: percent of total with ALLSELECTED. Let's continue.

Frequently asked questions

What does RANKX do?

It returns the rank of the current row’s expression among the values computed for each row of a table.

Why ALL ( City )?

So every city competes in the ranking even when the visual filters to one city — classic pattern; variants exist.

ASC or DESC?

DESC for “highest sales = rank 1”; ASC for lowest-first rankings.

Ties?

Equal values can share ranks; learn dense vs skip when you need exact leaderboard rules.

RANKX vs TOPN?

RANKX assigns a number; TOPN returns a table of top items — different tools.

Course lesson?

Ranking with RANKX and TOPN in the DAX chapter.