A file lands in your lap: 40,000 rows, exported from three systems that never agreed on anything. Before you pivot it, chart it, or paste it into a dashboard, you have one job — decide what "the same row" means. Skip that and every number downstream is fiction.
This is the checklist I run on exports before I trust a single total. It is not about which button removes duplicates; it is about the order of operations.
1. Decide the key before you touch anything
Remove Duplicates asks you which columns define a duplicate. That question is a business question wearing a spreadsheet costume.
- An invoice is the same invoice if
invoice_idmatches, regardless of anything else. - A customer is the same customer if
emailmatches, usually. Sometimes it isemailORtax_id. - A line item is the same line item if
invoice_id+sku+line_nomatch together.
Write the key down before you click. If you cannot state it in one sentence, you are not ready to deduplicate — you are ready to ask someone.
2. Normalise the key columns first
The most common failure is not duplicates at all. It is the same value wearing two costumes:
"Acme Ltd" vs "Acme Ltd " "ACME LTD" vs "Acme Ltd" "a@b.com" vs "A@B.com" Excel sees four different values. Your database sees four customers.
Clean the key columns before comparing:
=TRIM(SUBSTITUTE(A2, CHAR(160), " ")) =LOWER(TRIM(C2)) CHAR(160) is the non-breaking space. It survives copy-paste from web pages and looks exactly like a normal space. It has cost me an afternoon more than once.
If your data came from a SQL export, do the normalisation in SQL instead — LOWER(TRIM(col)) in the SELECT — and skip the spreadsheet step entirely.
3. Add a helper column, do not delete yet
Never run Remove Duplicates on the live sheet first. Add a marker column:
=COUNTIFS($B$2:$B$40000, B2, $C$2:$C$40000, C2) Every row now carries how many times its key appears. Sort descending on that column and the duplicates surface at the top, in context, next to the rows they collide with.
This one step answers the question that matters: are these true duplicates, or are they legitimate repeat events? Two invoices for the same customer on the same day might both be real. Two invoice records with the same invoice_id cannot be.
4. Pick the surviving row on purpose
When duplicates are real, you still have to choose which copy to keep. The newest? The one with a non-empty phone number? The one whose status is not void?
A sort handles this cleanly:
- Sort by key ascending, then by
updated_atdescending. - In a helper column, flag
=COUNTIFS($B$2:B2, B2) = 1— this marks only the first row of each key group. - Filter the flag to
TRUE, copy what is left into a new sheet.
That is a dedupe with a documented rule. Six months from now you can explain exactly why a given row survived, which is more than Remove Duplicates will ever tell you.
5. Keep the rejects
Copy the removed rows to a sheet called removed_YYYYMMDD. It costs nothing and it saves you when someone says "the total dropped by 12k, why?"
You will have the answer in one filter instead of re-running the export.
6. Re-check the total, not the row count
After deduplication, compare the sum of your money column before and after. If the difference is not explainable by the count of removed rows times a plausible average, something went wrong — probably a key column with blanks, because COUNTIFS treats blank as a value and happily collapses every blank-keyed row into one group.
Blanks in a key column are the single most expensive mistake in this whole process. Filter for them before step 3 and fix them by hand.
The SQL version, if you live there
If the export is going into a database anyway, do not deduplicate in Excel at all:
WITH ranked AS ( SELECT *, ROW_NUMBER() OVER ( PARTITION BY invoice_id ORDER BY updated_at DESC ) AS rn FROM raw_invoices ) SELECT * FROM ranked WHERE rn = 1; Same logic, same explicit rule about which row survives, none of the copy-paste risk. I reach for Excel when the data is small and the question is exploratory, and for SQL when the answer has to be reproducible.
The short version
- State the key in one sentence.
- Normalise the key columns — trim, lower, kill
CHAR(160). - Flag with
COUNTIFS, do not delete. - Keep the first row per key by an explicit sort rule.
- Save the rejects in a dated sheet.
- Re-check the money total, not just the row count.
Deduplication is not a button. It is a decision about identity, made once, written down, and applied consistently. The button is just the last step.
