← All challenges

D5 · DAX · Filter context · about 20 min

Rank Players

medium

Scouts compare a handful of players at a time by picking them in a slicer. The ranking column shows 1 for every player, and after a first fix a shortlist of three shows ranks in the teens and forties instead of 1, 2 and 3.

Your task

Create a measure named [Player Rank]: each player's rank by total runs (1 = most runs) among the players currently selected. It must respond to the Player and Season filters, and stay blank for a player with no runs in the current filter.

What the grader checks

You see the situations, not the expected numbers. The expected values are computed live from your file and the source data.

  • T1Player slicer: 5 players
    Five players from different teams picked in the Player slicer, all seasons.
  • T2Same 5 players, Season 2025
    The same five players with the Season slicer set to 2025. The order changes.
  • T3One team's roster
    Players filtered to one team's roster (a filter on the Players table).
  • T4Whole league, 2024
    Every player, Season 2024. Players who did not bat must stay blank, not get a rank.

Stuck?

Open one hint at a time.

Hint 1

RANKX compares the current player with a list of players. Which list does it see if you give it the Players table inside a row that is already filtered to one player?

Hint 2

The list should be the players selected on the page, not one player and not the whole league. Also check that the expression is evaluated for each player in that list: SUM alone does not switch to the player being ranked.

Hint 3 (near-answer)

RANKX( ALLSELECTED( Players[Name] ), CALCULATE( SUM( Batting[Runs] ) ) ), wrapped in IF so a player with no runs stays blank.

Show the editorial

Solve it first if you can: the editorial gives the answer away.

The trap

Inside a table visual each row is already filtered to one player, so RANKX( Players, ... ) ranks that player against a list of one: everyone is 1. Writing SUM without CALCULATE gives the same result, because the sum is not re-evaluated for each player in the list. Swapping in ALL( Players ) fixes the 1s but ranks against the whole league, so a shortlist of three shows ranks like 12, 31 and 47.

The fix

IF( NOT ISBLANK( SUM( Batting[Runs] ) ), RANKX( ALLSELECTED( Players[Name] ), CALCULATE( SUM( Batting[Runs] ) ) ) ).

Why it works

RANKX needs two things: the list to rank within, and a value for each item in that list. ALLSELECTED removes the one-player filter of the current row but keeps the page's own selection, so the list is the players picked in the slicer. CALCULATE turns each player in that list into a filter, so the runs are that player's runs. The IF keeps players who did not bat out of the ranking instead of placing them last.

A rank needs a list and a per-item value. Decide the list (selected players: ALLSELECTED) and make sure the value moves with each item (CALCULATE).