Search…

DAX Functions

How to Use the RANKX Function in Power BI: The Ultimate Guide

How to Use the RANKX Function in Power BI: The Ultimate Guide

Learn how ranking works in DAX using the RANKX function in Power BI. Explore real examples, tie-breaking methods, filter context behavior, and best practices for dynamic ranking.

Learn how ranking works in DAX using the RANKX function in Power BI. Explore real examples, tie-breaking methods, filter context behavior, and best practices for dynamic ranking.

Written By: Sajagan Thirugnanam and Austin Levine

Last Updated on February 19, 2026

Introduction

Ranking is one of the most common requirements in Power BI reporting.

Whether you’re building a Top 10 products dashboard, ranking customers by revenue, or ranking countries by profit, you will almost always need one function: RANKX()

But here’s the issue: most Power BI users try RANKX once, get weird results (like blanks, duplicates, or incorrect ranks), and then avoid ranking completely.

In this guide, you’ll learn exactly how ranking works in DAX, how to use RANKX properly, and how to avoid the most common mistakes.

What Is RANKX in Power BI?

RANKX is a DAX function that assigns a rank (1st, 2nd, 3rd, etc.) to each row of a table based on a measure or expression.

It is used when you want to rank items such as:

  • Products by Sales

  • Customers by Profit

  • Employees by Performance

  • Regions by Revenue

  • Categories by Growth

Unlike Excel ranking formulas, RANKX is dynamic, meaning it changes depending on slicers, filters, and context.

That’s what makes it so powerful.

RANKX Syntax 

Here is the official structure:

RANKX( <table>, <expression>, [value], [order], [ties] )

Let’s break it down in plain English:

<table>

This is the list of items you want to rank.

Example: all products.

<expression>

This is what you want to rank by.

Example: Total Sales measure.

[value] (optional)

This is usually skipped. It tells Power BI what row to evaluate.

[order]

Defines if ranking is ascending or descending.

  • DESC → highest gets rank 1

  • ASC → lowest gets rank 1

[ties]

Defines what happens if two items have the same value.

  • SKIP (default)

  • DENSE

RANKX Example and Common Use Case in Power BI

Let’s assume you have a Sales table and a Products table. And you already have this measure:

Total Sales = SUM(Sales[SalesAmount])

Now you want to rank products by sales.

Product Rank = RANKX( ALL(Products[ProductName]), [Total Sales], , DESC )

What this does:

  • Looks at all products

  • Evaluates total sales for each

  • Assigns rank based on highest sales

Why ALL() Is Important in RANKX

This is one of the biggest mistakes people make.

If you write:

Product Rank = RANKX( Products, [Total Sales] )

The ranking may behave inconsistently depending on filter context.

Why?

Because Power BI might only rank the products currently visible in the visual.

So instead, we usually use:

  • ALL() to rank across all values

  • ALLSELECTED() to rank only within slicer selections

RANKX with ALL vs ALLSELECTED

This is one of the most searched ranking issues in Power BI.

Option 1: Rank Across Entire Dataset (Ignore Filters)

Rank Global = RANKX( ALL(Products[ProductName]), [Total Sales], , DESC )

This rank is global and ignores slicers.

Even if you filter to a region, the product still keeps its global rank.

Option 2: Rank Only Within User Selection (Dynamic Ranking)

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

This is usually what you want in dashboards.

If a user selects “Asia”, then ranking happens only within Asia.

When to Use ALL vs ALLSELECTED for Ranking

Here’s the simple rule:

Use ALL() when:

  • You want ranking across the full dataset

  • You want consistent ranks no matter filters

  • You are building KPI benchmarks

Use ALLSELECTED() when:

  • You want ranking to change with slicers

  • You want “Top N in current selection”

  • You are building interactive dashboards

Ranking by Profit Instead of Sales

Let’s say you have this measure:

Total Profit = SUM(Sales[Profit])

Then ranking becomes:

Profit Rank = RANKX( ALL(Products[ProductName]), [Total Profit], , DESC )

This is why measures are powerful, you can reuse the same ranking logic.

How to Rank with Ascending Order (Lowest Gets Rank 1)

Sometimes you want to rank from lowest to highest.

Example: ranking products by lowest profit.

Lowest Profit Rank = RANKX( ALL(Products[ProductName]), [Total Profit], , ASC )

Now the product with the lowest profit will get rank 1.

Handling Ties in RANKX (Dense vs Skip)

What happens if two products have the same sales?

Example:

Product

Sales

A

100

B

90

C

90

D

70

Default behavior = SKIP

Rank becomes:

  • A = 1

  • B = 2

  • C = 2

  • D = 4

Notice how rank 3 is skipped.

Dense ranking (No gaps)

Dense Rank = RANKX( ALL(Products[ProductName]), [Total Sales], , DESC, DENSE )

Now it becomes:

  • A = 1

  • B = 2

  • C = 2

  • D = 3

Which Tie Method Should You Use?

Use SKIP when:

  • Ranking should reflect true position gaps

  • Common in sports/competition ranking

Use DENSE when:

  • You want cleaner “Top N” filtering

  • Common in business dashboards

Most Power BI dashboards use DENSE because it feels more intuitive.

RANKX and Filter Context

The reason RANKX confuses people is because ranking happens inside a filter context.

If you filter the report to one region, then RANKX will rank only those products that remain in the filtered dataset (unless you override filters using ALL).

This is why understanding filter context is critical for mastering ranking.

Final Thoughts: Mastering Ranking in Power BI with RANKX

Ranking is one of the easiest and fastest ways to make your Power BI dashboards more useful.

Once you understand how RANKX interacts with filter context, you can build powerful reports like dynamic leaderboards, top-performing product lists and interactive Top N charts.

If your Power BI model is built correctly, RANKX becomes one of the cleanest and most powerful DAX tools.

FAQs

What does RANKX do in Power BI?

RANKX assigns a rank number to each row of a table based on a measure or expression, allowing you to sort and filter results dynamically.

How do I rank within a slicer selection?

You can do this by using ALLSELECTED function.

What is dense ranking in Power BI?

Dense ranking means ties share the same rank and the next rank number is not skipped. Example: 1, 2, 2, 3.

Related to DAX Functions

Want Power BI expertise in-house?

Get in Touch With Us

Turn your team into Power BI pros and establish reliable, company-wide reporting.

Berlin, DE

powerbi@casewhen.co

Follow us on

© 2026 CaseWhen Consulting
© 2026 CaseWhen Consulting
© 2026 CaseWhen Consulting