HomeGuides › Cleaning and comparing spreadsheets

How to clean a spreadsheet and compare two exports

Two jobs come up again and again with spreadsheets: tidying a messy export so it can be used, and working out what changed between last month's file and this month's. Both are done badly by eye and badly by hastily written formulas. Here is how to do each properly — and, just as importantly, which shortcuts quietly corrupt your data.

The five ways a spreadsheet quietly loses your data

Before any cleaning, it is worth knowing what goes wrong, because most of it happens silently — the file opens, the numbers look fine, and something is already wrong.

Each of these is why the Spreadsheet Cleanup & Reconciliation tool treats every value as text until you explicitly ask for it to be converted, and asks which way round your dates are written rather than choosing.

Part one: cleaning a file

Step 1: check how the file was read before you change anything

Most cleaning mistakes happen at the import, not during the work. Look at the preview and check three things:

Two headings with the same name, and headings that are blank, are normal in exports. They should be kept apart and labelled, never merged: if two columns are both called Amount, collapsing them loses one of them completely.

Step 2: tidy the text

Trailing spaces are the single most common reason two apparently identical values refuse to match. Trim first, and look at what the trim reports: if it changed hundreds of values, that tells you something about how the file was produced.

Collapsing repeated spaces and converting non-breaking spaces are separate decisions. A non-breaking space is invisible and extremely common in data copied from web pages or PDFs, and it will not match an ordinary space.

Step 3: deal with duplicates deliberately

Decide what makes two rows the same before you remove anything. Duplicates by whole row are safe to remove. Duplicates by a key column — two rows with the same invoice number — are usually a sign of a real problem, and deleting one silently hides it. Marking them and looking at them first is nearly always the right move.

Whatever you remove, keep it. A cleaning step that discards rows with no way to see them again is a step you cannot check.

Step 4: convert dates and numbers last, and only where you mean it

Conversion is the step that cannot be reversed by looking at the result, so leave it until the shape of the data is right. Convert a column only when you know what is in it: a column of dates in one format, a column of amounts in one convention. Anything that fails to convert should be left exactly as it was and listed, not blanked — a value the tool could not read is information, and replacing it with nothing destroys that.

Part two: comparing two exports

Step 1: choose a key, and check it

A comparison is only as good as the column that identifies a row. An invoice number, an SKU, a member ID, an email address. Before comparing, check two things about it:

Step 2: decide what counts as the same

By default, compare keys exactly: ABC  and abc are different. Ignoring case or trailing spaces is often the right thing, but it must be a decision you made and one that appears in the report, because it changes which rows are considered to be the same record.

Step 3: set a tolerance where a tolerance is honest

Amounts that came through different systems can differ by a penny from rounding. Allowing a difference of 0.01 is reasonable; allowing 1.00 is hiding real differences. Whatever you allow, the actual values should still be shown, so a "within tolerance" row can be checked rather than trusted.

Step 4: read the six groups

Every row on both sides should land in exactly one of these, with nothing left over:

The check that matters is arithmetic: the groups should add up to the number of rows you started with on each side. If they do not, rows have been duplicated or dropped somewhere in the comparison.

Step 5: mind the difference between blank, zero and absent

These three are not the same thing and a comparison should never treat them as one. A field that was empty and now holds 0 has changed — someone entered a figure. A row that is absent from the later file is not a row whose values became blank. Reports that flatten all three into "empty" are the reason reconciliations get signed off with real changes hidden inside them.

Before you send the results to anyone

Doing it without uploading anything

Spreadsheets of invoices, members or staff are exactly the kind of file that should not be posted to a website to be processed. The Spreadsheet Cleanup & Reconciliation tool does all of the above in your browser: the file is read by code running on the page, nothing is sent anywhere, nothing is stored, and every result is a new file you download yourself.

Related: Developer & Data tools for converting between JSON and CSV, and Text Compare when what you are comparing is prose rather than a table.