RANKX

Power BI · Advanced DAX & Time Intelligence

Theory

RANKX(table, expression, value, order, ties) ranks the current item by evaluating the expression for every row of the table and finding where the current value falls. In practice you iterate over all items of a dimension, so the ranking ignores the visual's own filter on that dimension: Customer Rank = RANKX(ALL(Customers[Name]), [Total Sales]). The default order is descending (largest value = rank 1).

With the sample data, Asha (₹2,700) ranks 1, Ravi (₹2,400) 2, Meera (₹600) 3 and Karan (₹500) 4. The ties argument decides what happens with equal values: Skip (the default) gives 1, 1, 3, while Dense gives 1, 1, 2. A common mistake is RANKX(Customers, [Total Sales]) without ALL: inside a visual by Name, the table contains only the current customer, so everyone gets rank 1. Use ALLSELECTED instead of ALL if the ranking should respect slicers on that dimension.

Why we use it

Top-N lists, leaderboards and 'where do we stand' questions all need ranks. RANKX gives dynamic ranks that update with slicers on other dimensions such as Year or Region.

When to use it

Use RANKX for ranking items in visuals or filtering a Top N with a measure. For a simple 'top 5 by value' on one visual, the visual-level Top N filter is quicker. Add a check like IF(ISINSCOPE(...)) to hide the rank on total rows.

How it works

  1. Visual row for a customer
  2. Evaluate [Total Sales] for the current customer
  3. Evaluate [Total Sales] for every customer in ALL(Customers[Name])
  4. Count how many values are larger
  5. Are there ties? Yes: Apply Skip or Dense rule. No: Rank = larger values + 1.
  6. Rank shown per row

Syntax

RANKX(<table>, <expression>[, <value>[, <order>[, <ties>]]])
order: DESC (default) | ASC
ties: Skip (default) | Dense

Example

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

// Hide on the total row
Customer Rank (clean) = 
IF(ISINSCOPE(Customers[Name]), RANKX(ALL(Customers[Name]), [Total Sales]))

Key points

Power BI topics

Power BI Introduction

Getting Data

Power Query (Data Transformation)

Data Modeling

DAX (Data Analysis Expressions)

Data Visualization

Dashboards & Reports

Power BI Service

Advanced Features

Projects & Case Studies

Interview & Certification

Advanced DAX & Time Intelligence

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Power BI Dashboards & DAX

Learn data visualization and interactive dashboards step-by-step. Click any topic in the sidebar to open it right here.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice DAX Online 250 business scenarios on a star schema — write a measure and compare your visual with the expected one. Start practising →
Section {{ sec.num }}

{{ sec.label }}

Power BI  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
On screen — where to click

{{ rich.ui.title }}

{{ u.text }}
  1. {{ st.n }}{{ st.text }}
{{ rich.ui.title }}
{{ u.text }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax / Where to find it
{{ current.syntax }}
Example
{{ current.example }}
What You'll Learn — click to check off
  • {{ pt.mark }} {{ pt.text }}

Share this topic