P1 · Power Query · about 15 min
Clean Team Names
easyThe scheduling system exports games with the team typed as free text: "Harbor Hawks", "harbor hawks", " Harbor Hawks", "HARBOR HAWKS". The analyst merged it with the Teams table to get each game's TeamID, and 294 of the 600 games came back with no team.
Your task
Load Games_by_team_name.csv from the SourceFolder folder as a table named Games with columns GameID (whole number), Date (date), Season (whole number) and TeamID (whole number), where TeamID comes from merging the team name with the Teams table. Every game must get its TeamID.
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.
- T1Every game has its team
Games compared row by row with the source file, matched on GameID: every game must carry the TeamID of its team.
Stuck?
Open one hint at a time.
Hint 1
Merge Queries only joins rows whose keys are exactly equal. Look at the distinct values of Team before the merge: how many spellings does each team have?
Hint 2
Two things differ between the spellings: letter case and spaces at the start or end. Fix both before the merge, not after.
Hint 3 (near-answer)
Select the Team column, Transform > Format > Trim, then Transform > Format > Capitalize Each Word. Then merge with Teams on Team and expand TeamID.
Show the editorial
Solve it first if you can: the editorial gives the answer away.
The trap
Power Query compares text exactly: "Harbor Hawks", "harbor hawks" and "Harbor Hawks " are three different keys, so a merge matches only the rows typed exactly like the Teams table. Fixing one problem is not enough: Capitalize Each Word leaves the stray spaces, and Trim leaves "HARBOR HAWKS" and "harbor hawks". Either way some games come back with a null TeamID and their runs land on a blank team.
The fix
Trim the Team column, then Capitalize Each Word (Text.Proper(Text.Trim(_))), then merge with Teams and expand TeamID.
Why it works
Trim removes the spaces at the start and end, and Capitalize Each Word turns every casing into the one the Teams table uses. Once the keys are identical, every row finds its team. Merging on the ID also means the model relates Games to Teams on a number, not on text.
Clean a text key before you merge on it: trim it and fix its case. Power Query merges are exact.