Menu

Chapter 06 · Keeping it honest · 7 min

Keep raw and summary apart

Here is the single most destructive habit in spreadsheet work, and almost everybody starts out with it: you are handed a file, you spot something wrong in it, and you fix it in place. A city name corrected. A stray total deleted. An amount that looked like a typo, adjusted.

Every one of those is a change with no record. There is no diff, no history, nothing to compare against the file you were sent. If somebody asks next month why your number differs from theirs, you have no way to find out — because the version that would have told you is gone.

The habit that replaces it is structural rather than careful: raw data goes in one block, your work goes in another, and formulas only ever read leftwards.

The grid

Seven orders in A1:C8 — this is the raw block, exactly as it arrived, mistakes included. Everything you run below writes into columns E and F, which is where the summary lives. Nothing touches columns A to C.

Build the summary's labels, do not type them

A summary needs a row per city. The tempting move is to look at the raw block, see three cities, and type them into column E.

Don't. A typed label is a copy of what the data looked like on the day you typed it, and it will not notice when a fourth city appears — or when the third one was never quite what you thought.

UNIQUE derives the list instead. It reads the raw column and spills one row per distinct value, and it is the first thing in this track that will answer a question you did not ask.

Run it and read the four rows it produces, carefully.

There are three city names in that column as far as anyone reading it can tell. How many rows does the list come back with?

E2

Scroll to see all 6 columns →

ABCDEF
1order_idcityamount_myr
21001Kuala Lumpur38.50=UNIQUE(B2:B8)
31002Penang22.00
41003Kuala Lumpur51.25
51004 Penang44.00
61005Johor Bahru17.90
71006Penang19.50
81007Kuala Lumpur26.00
Editable, try changing it

The fourth city

Four rows, and two of them say Penang.

The order in row 5 carries a leading space — " Penang" rather than "Penang". On the grid the two are indistinguishable; the space occupies the same nothing that the left-hand edge of the cell does. LEN is the cheapest way to see it, because it counts characters and characters are not a matter of opinion.

Run it on the padded cell. Then change the reference to B3, the clean Penang two rows above, and watch the number drop by one.

Characters in the padded city name

In F3, count the characters in the padded city name, then point the same formula at the clean Penang above it and compare.

F3

Scroll to see all 6 columns →

ABCDEF
1order_idcityamount_myr
21001Kuala Lumpur38.50
31002Penang22.00
41003Kuala Lumpur51.25
51004 Penang44.00
61005Johor Bahru17.90
71006Penang19.50
81007Kuala Lumpur26.00

What the summary does with it

Criteria matching is exact. " Penang" is not "Penang", so a total built the obvious way silently covers two of the three Penang orders and leaves the third somewhere else — which is to say, nowhere.

This is the number that ends up in an email. It is plausible, it is confidently formatted, and it is short by one order.

Run the Penang total. Then add up the three Penang amounts on the grid by hand — 22.00, 44.00 and 19.50 — and compare.

By hand the three Penang orders come to 85.50. Does the formula agree?

F4

Scroll to see all 6 columns →

ABCDEF
1order_idcityamount_myr
21001Kuala Lumpur38.50
31002Penang22.00
41003Kuala Lumpur51.25=SUMIFS(C2:C8,B2:B8,"Penang")
51004 Penang44.00
61005Johor Bahru17.90
71006Penang19.50
81007Kuala Lumpur26.00
Editable, try changing it

The check that catches it

A summary block earns its keep by being checkable against the raw block it came from. Every order belongs to exactly one city, so the city totals must add up to the grand total. If they don't, the difference is not a rounding artefact — it is orders that fell out of every bucket.

So take the raw total and subtract each city total from it. On a summary that covers everything, the answer is zero. Here it will not be, and the number it returns is not a vague warning: it is the missing money, to the cent, which is usually enough to find the row on sight.

The formula below is deliberately long. A reconciliation line is the one place in a sheet where spelling the arithmetic out beats being clever.

If the summary covered all seven orders this would be zero. What number comes back instead, and which order on the grid is it?

F5

Scroll to see all 6 columns →

ABCDEF
1order_idcityamount_myr
21001Kuala Lumpur38.50
31002Penang22.00
41003Kuala Lumpur51.25
51004 Penang44.00=SUM(C2:C8)-SUMIFS(C2:C8,B2:B8,"Kuala Lumpur")-SUMIFS(C2:C8,B2:B8,"Penang")-SUMIFS(C2:C8,B2:B8,"Johor Bahru")
61005Johor Bahru17.90
71006Penang19.50
81007Kuala Lumpur26.00
Editable, try changing it

The repair goes in a new column

Now the fix — and the whole point of this chapter is where it goes.

TRIM removes leading and trailing spaces from a piece of text. The instinct is to run it, look at the tidy result, and type that result over cell B5. Thirty seconds, one cell, problem gone.

And the evidence is gone with it. Nobody can now tell that the file arrived with a padded value, which means nobody fixes it upstream, which means it arrives padded again next month and you spend the thirty seconds again — this time not knowing you have already found it once.

The working version costs one column. A new column D, =TRIM(B2) filled down, and every summary formula points at D instead of B. Column B is never touched, the two sit side by side, and the difference between them is a permanent record of what the source got wrong.

TRIM strips the spaces from the ends of a piece of text. What does it give back for that cell?

F6

Scroll to see all 6 columns →

ABCDEF
1order_idcityamount_myr
21001Kuala Lumpur38.50
31002Penang22.00
41003Kuala Lumpur51.25
51004 Penang44.00
61005Johor Bahru17.90=TRIM(B5)
71006Penang19.50
81007Kuala Lumpur26.00
Editable, try changing it

Three blocks, one direction

The layout that makes all of this automatic is three blocks on one sheet, left to right:

  • Raw. Exactly what you were given. Nothing is typed into it, ever, including corrections you are certain about.
  • Working. The cleaned columns, every one of them a formula reading from raw. If the source file is replaced next month, this recomputes and you do nothing.
  • Summary. The numbers somebody asked for, reading from working, with a reconciliation line at the bottom that must come to zero.

Formulas point one way only — summary reads working, working reads raw, and nothing ever reads back the other direction. A sheet built like this can be handed to someone else, because every number in it can be traced to a cell they can see. A sheet where the corrections were typed in cannot, no matter how careful the person typing was.

A real Excel file would give each block its own sheet tab, which is tidier. The rule is identical either way, and the engine running these examples has one sheet, so blocks side by side is how this grid shows it.

Next in this track: the two things everybody does to a table without thinking — sorting it and filtering it — and what each one quietly does to the numbers already on the page.

Sign in to track your progress.