D2 · DAX · DAX basics · about 10 min
Players Who Batted
easyThe coaching staff wants to know how many different players got a turn at bat. The first draft of the report says Harbor Hawks used 1,080 players in two seasons. The roster has 15.
Your task
Create a measure named [Players Who Batted]: the number of different players who batted in the current filter. It must respond to the Team, Season, Month and Game filters.
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.
- T1By team
One row per team that has played games. - T2One team by month
Harbor Hawks in the 2024 season, one row per month. - T3A single game
Filtered to one game. - T4Whole league
No filters at all: the league total, which leaves out players who never batted.
Stuck?
Open one hint at a time.
Hint 1
One row of Batting is one player in one game. If a player bats in 120 games, how many rows do they have?
Hint 2
You want each player counted once, however many games they played. Which DAX function counts different values?
Hint 3 (near-answer)
DISTINCTCOUNT on Batting[PlayerID]. Count it from Batting, not from Players: the Players table lists the roster, including people who never batted, and Team filters do not reach it.
Show the editorial
Solve it first if you can: the editorial gives the answer away.
The trap
COUNTROWS( Batting ) or COUNT( Batting[PlayerID] ) counts appearances: nine per game, so 1,080 for a team that played 120 games. Counting the Players table goes wrong the other way: it counts the whole roster, including the expansion team's players who never batted, and it does not change with the Team filter because Teams only reaches Batting through Games.
The fix
DISTINCTCOUNT( Batting[PlayerID] ). Count the different player IDs among the batting rows the filter leaves.
Why it works
The question is about people, but the table is about appearances. Counting rows answers "how many times", counting distinct IDs answers "how many different". Counting from Batting also means the measure follows every filter that reaches Batting: team, season, month or a single game.
Say the noun in the question. "How many players" is a distinct count of the player key in the fact table, not a row count.