DEV Community

Cover image for The Monday report problem: killing hand-built spreadsheets with SQL views
Mario Fang
Mario Fang

Posted on Originally published at mariosfong.hashnode.dev

The Monday report problem: killing hand-built spreadsheets with SQL views

The Monday report problem: killing hand-built spreadsheets with SQL views

Every Monday morning someone in the office opens a spreadsheet that is older than some of the people working here, and starts pasting numbers into it. The problem with that file is not that it is slow. It is that nobody can prove the numbers on it are right without rebuilding the whole thing by hand, and that is the actual cost of a hand-built report.

I have watched this cycle for years. The file gets updated by whoever is at their desk on Monday. It gets emailed around. Two people keep local copies with slightly different names. Then a figure changes somewhere upstream, and one of those copies is wrong in a way that nobody notices for a month.

A hand-built report is a claim, not a measurement

When you paste numbers into cells, what you are really doing is making a statement: this is what the data said when I looked. That statement is only true for the minute it was made. It carries no memory of where the numbers came from, no filter that can be re-run, and no way for the next person to check it without repeating the same manual work.

A measurement is different. A measurement can be re-performed. If someone questions a number in a view, you point at the query, they read the filter, and the argument is over in a minute. If someone questions a number in a pasted sheet, the only honest answer is "let me go redo it and see if I get the same thing" — and that answer costs you the whole afternoon.

The paste is the cheap part; the proof is what costs you

People usually describe this as a time problem. Re-export, re-paste, re-check, three hours gone. But three hours on Monday is not what hurts. What hurts is that every figure in that file has to be defended from scratch, every month, by the one person who remembers how it was built.

That person is a single point of failure, and they know it. Which is why the file gets more elaborate every year: more tabs, more colours, more footnotes explaining which row was adjusted by hand. None of that is documentation. It is a warning label.

Move the logic out of someone's memory and into the schema

The fix is not a better spreadsheet. It is moving the repeated part — the pulling, joining, filtering, summing — into a view in the database, where it lives once and runs every time someone opens it.


A view is just a saved query with a name. You define what a completed order means once: which statuses count, which dates bound the period, which rows are test data and must be excluded. Then every report, dashboard and export reads from that definition instead of from someone's recollection of it.

The work is mostly deciding, not typing. Half of building a view is sitting with the person who owns the report and asking: why is this row here, why is that one missing, what do we do with the order that shipped in January and was credited in February. Those questions have answers. They are just stored in a person instead of a system, which is why they never survive a holiday.

A date filter belongs in the query, not in a person's habit

The single most common failure I see in hand-built reports is period logic. Someone filters "last month" by eyeballing a date column. Someone else includes the first day of the following month because that is when the invoice landed. Both are reasonable, and together they are unreconcilable.

In a view you decide the rule once: which date field defines the period, whether the boundary is inclusive, and which timezone you mean. After that the number is the same for everyone who asks, which is the entire point. A report that two people can compute two ways is not a report — it is a negotiation.

The test is whether someone else can re-run it

Here is the check I use, and it takes about ten minutes:

  1. Hand the report to a colleague who has never built it, with no verbal explanation.
  2. Ask them to tell you what the total would be for a different month.
  3. If they have to open a spreadsheet and start pasting, the report failed.

A view passes that test because the answer is a parameter away. It also passes a second test that matters more: when someone asks why a number moved, you can show the change in the source data instead of guessing.

None of this makes the report prettier, and it will not save you time in the first month — writing the view takes longer than pasting. What it buys is that the second month, the fifth month, and the month after the person who built it has left, the number still comes out the same way, and anyone can check it.

That is the trade I keep making: pay once for the definition, then stop paying for the proof.

— Mario

Top comments (0)