Lesson 2.2: Check the spreadsheet
Download: city-report.xlsx. We made it with three mistakes on purpose.
Someone sends you a workbook about your city. Are the figures right? A spreadsheet that opens without errors can still be wrong.
| Figure on the report | Value |
|---|---|
| Total population | 48,620 |
| Home tax rate, month 12 | 15% |
| Total income | 378,080 |
LOAD excel;
SET VARIABLE game = (SELECT game_id FROM dim_game ORDER BY started_utc DESC LIMIT 1);
(INSTALL excel; once, if you have not.)
By hand
1. Read the sheet
SELECT * FROM read_xlsx('city-report.xlsx', sheet = 'Report', all_varchar = true);
2. Population: take one month
SELECT SUM(population) AS people
FROM rpt_region_month
WHERE game_id = getvariable('game') AND owner = 'You' AND month = 35;
2,660. The report added every month.
3. Tax: weight it
SELECT ROUND(100 * SUM(tax_r * built_r) / SUM(built_r), 1) AS weighted_pct
FROM rpt_region_month
WHERE game_id = getvariable('game') AND owner = 'You' AND month = 12;
19%. The report took a plain average of two rates.
4. Income: find the gap
SELECT region, SUM(income) AS income
FROM rpt_region_month
WHERE game_id = getvariable('game') AND owner = 'You'
GROUP BY region ORDER BY region;
Together 448,928. The report is short by 70,848: exactly Ridge. The formula added Harbor and Midland, and Ridge came later.
5. Is the data right?
SELECT
(SELECT COUNT(*) FROM read_xlsx('city-report.xlsx', sheet = 'Data')) AS sheet_rows,
(SELECT COUNT(*) FROM rpt_region_month WHERE game_id = getvariable('game')) AS db_rows,
(SELECT SUM(income) FROM read_xlsx('city-report.xlsx', sheet = 'Data')) AS sheet_income,
(SELECT SUM(income) FROM rpt_region_month WHERE game_id = getvariable('game')) AS db_income;
108 rows each, 483,320 each (all players). The data is fine; the formulas are wrong.
The method: get the figure from the source, compare, find out why it differs.
With AI (optional)
In the video this starts at 3:06. No AI tool? Skip to Practice (4:27). Use copies. What the AI reads is sent to its provider, and that includes the workbook.
Asked: "Are the figures on the Report sheet right?" In a real run on 2026-12-05 (Claude) it found all three wrong, with the same correct values, and compared the data sheet with the database. Ask to see the check it ran for each figure.
With Data Studio (optional)
In the video this starts at 3:48. No Data Studio? Skip to Practice (4:27). It does not read the workbook. Ask it for the three source figures (2,660, 19%, 448,928) and compare them yourself.
Practice
- How much cash did you hold in month 35?
- How much income did the report leave out?
- How many months of data are in the sheet?
Answers (sample file)
1. 478,011. 2. 70,848. 3. 36. Queries: lesson-2.2-queries.sql, P1 to P3.