Power BI Advanced AnalyticsLesson 33 of 53
Lesson 33 of 53

Relationship Navigation: RELATED & RELATEDTABLE

Overview & Learning Objectives

Business executives love leaderboards: "Who are our Top 10 stores?" or "Rank our sales executives by quota attainment." In DAX, ranking is accomplished using the formidable `RANKX()` function. Understanding its 5 parameters—especially table scope with `ALL()`, ordering (DESC vs ASC), and tie-breaking (Dense vs Skip)—ensures your leaderboards never break.

  • Master all 5 parameters of the `RANKX(Table, Expression, [Value], [Order], [Ties])` function.
  • Explain why `ALL(Dim_Store[StoreID])` is required as the first argument in visual matrix rankings.
  • Contrast "Dense" ranking (1, 2, 2, 3) with "Skip" ranking (1, 2, 2, 4).

Industry Standard

Standard: Analytics standards at Amazon and Flipkart require wrapping `RANKX` in `IF(ISBLANK([Measure]), BLANK(), ...)` to prevent unranked entities with zero sales from cluttering leaderboards.

Real-World Example: FreshBake Artisan Patisserie

FreshBake ranks outlet managers based on monthly revenue. Two outlets tie for 2nd place with ₹ 2,00,000 in sales.

Outlet NameMonthly Revenue (₹)RANKX with Skip (Default)RANKX with Dense
Indiranagar Main3,50,000Rank 1Rank 1
Koramangala Outlet2,00,000Rank 2 (Tie)Rank 2 (Tie)
Whitefield Outlet2,00,000Rank 2 (Tie)Rank 2 (Tie)
Airport Kiosk1,20,000Rank 4 (Skips 3!)Rank 3 (No gap!)

Syntax & Core Workflow

Store Rank = 
IF(
    ISBLANK([Total Sales]), 
    BLANK(), 
    RANKX(ALL(Dim_Store[StoreName]), [Total Sales], , DESC, Dense)
)

Parameters Breakdown

  • Table: The entire set of entities to rank against; usually wrapped in `ALL()` so visual rows know all competitors.
  • Expression: The measure used to rank (e.g. `[Total Sales]`).
  • Value (Optional): Rarely used; the value to rank against. Leave empty (comma comma) to rank current row.
  • Order (Optional): `DESC` (highest is Rank 1, default) or `ASC` (lowest is Rank 1).
  • Ties (Optional): `Skip` (e.g. 1, 2, 2, 4) or `Dense` (e.g. 1, 2, 2, 3).

Sample Walkthrough (Q&A)

Question: Why does RANKX return "Rank 1" on EVERY row of a visual table if you forget to use ALL()?

Formula / Action: Without ALL(), the table argument only sees the single current row in its filter context.

Result: Every store compares itself only against itself and awards itself Rank 1!

Explanation: In a visual table, each row is filtered to that specific store. Passing `ALL(Dim_Store[StoreName])` strips the row filter, allowing RANKX to compare that store against all other stores.

Common Mistakes & Limitations

  • Omitting `ALL()` in the first argument, resulting in Rank 1 across every single row of a leaderboard.
  • Passing `Fact_Sales` into RANKX instead of `Dim_Store[StoreName]`, causing massive memory slowdowns.

Keyboard Shortcuts

ActionWindowsMac
Quick Measure: Rank ValueQuick Measure -> Mathematical -> Star RankingQuick Measure
Format OutputMeasure Tools -> Whole NumberWhole Number

Pro Tips & Modern Alternatives

  • Use the modern DAX visual calculation `RANK()` or `ROWNUMBER()` introduced in recent Power BI Desktop updates for simplified visual-only ranking.
  • Combine `RANKX` with `TOPN()` to build dynamic Top 5 or Top 10 customer charts.