D1 · DAX · DAX basics · about 10 min
Runs per Game
easyThe league office wants a table of how many runs each team scores per game. An analyst built it with AVERAGE on the Runs column and every team shows about 0.5 runs per game. A real baseball team scores 4 or 5.
Your task
Create a measure named [Runs per Game]: the average number of runs a team scores per game. It must respond to the Team, Season and Month filters, and must stay blank where there are no games.
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
A table with one row per team (three teams that have played games). - T2Season slicer: 2024
Season slicer set to 2024, one row per team that has played games. - T3By month
One row per month in the 2025 season. - T4Blank, not zero
All six teams listed, including the expansion team with no games. Where there is nothing to average the measure must stay blank, not show 0.
Stuck?
Open one hint at a time.
Hint 1
Think about what one row of the Batting table is. It is one player in one game, not one game. What does AVERAGE do with those rows?
Hint 2
You need total runs divided by the number of games. Batting has a GameID column; count how many different games are in the current filter.
Hint 3 (near-answer)
SUM( Batting[Runs] ) divided by DISTINCTCOUNT( Batting[GameID] ). Wrap it in DIVIDE, and do not add anything that turns a blank result into 0.
Show the editorial
Solve it first if you can: the editorial gives the answer away.
The trap
AVERAGE( Batting[Runs] ) averages over player-game rows. Each game has nine batters and most score no runs, so the result is about 0.49 instead of the 4.44 runs a team scores per game. The numbers look plausible at a glance, and nothing errors. A second trap is making the empty case friendly: the expansion team has no games, and adding + 0 or COALESCE shows 0 runs per game for a team that has not played.
The fix
DIVIDE( SUM( Batting[Runs] ), DISTINCTCOUNT( Batting[GameID] ) ). Total runs over the number of games in the current filter. Leave blank results blank.
Why it works
AVERAGE divides by the rows in the table, and the grain of Batting is player per game. The unit you want to divide by is a game, so count distinct games. For a team with no games both pieces are blank, and blank divided by blank is blank, which is the honest answer: there is no average, not an average of zero.
Before you average, name the unit. The denominator must be the thing the sentence is about (per game), not whatever the table has one row of.