Sub topic 14
Check the cleaned data before you trust it
This chapter assumes you have already used Trim whitespace, Remove duplicates, Split text to columns, and the matching formulas (TRIM, CLEAN, UNIQUE, SPLIT, REGEXREPLACE). It also assumes you kept an untouched copy of the raw data on its own sheet. Here you will test the result so you know the cleanup worked and did not quietly damage anything.
Why a cleanup needs its own checks
Cleanup tools fail silently. Remove duplicates reports a count and moves on. TRIM never warns you about a non-breaking space it left behind. SPLIT puts a surname in the wrong column and shows no error. A sheet that looks tidy can still break a lookup or a pivot table next week.
Verification means asking measurable questions of the cleaned data and comparing the answers with what you expected before you started. Each check below returns a number, and that number should be zero or match a value you can predict.
Set up a Checks sheet
Keep the checks in one place so you can rerun them after every cleanup pass. The examples assume this layout:
- A sheet named
Rawholds the untouched import, with headers in row 1. - A sheet named
Cleanholds the cleaned result, also with headers in row 1. - A third sheet named
Checksholds one formula per check, with a label in column A, the formula in column B, and the expected value in column C.
A check that never fails teaches you nothing. Before you trust one, break a copy of the data on purpose (add a trailing space, say) and confirm the check catches it.
Check 1: the row count
Row counts are the cheapest and most useful check. Count the non-empty cells in a column that is always filled:
=COUNTA(Raw!A2:A)=COUNTA(Clean!A2:A)The difference must equal the number of duplicates you intended to remove. If you flagged duplicates with =COUNTIF($A$2:A2, A2) > 1, count the TRUE values in the helper column with =COUNTIF(F2:F, TRUE). Then compare:
=COUNTA(Raw!A2:A) - COUNTIF(Raw!F2:F, TRUE) - COUNTA(Clean!A2:A)This should return 0. A positive result means the cleanup removed fewer rows than expected. A negative result means it removed more, and that is the more dangerous case because real records may be gone.
If you only trimmed, split, or changed case, the row counts must be identical.
Check 2: leftover spaces
Compare each cell's length with the length of its trimmed version. If they differ, the cell still has extra spaces:
=SUMPRODUCT(--(LEN(Clean!A2:A) <> LEN(TRIM(Clean!A2:A))))The expected result is 0. Run this on every text column, not only the first one. Change the column letter and keep the rest the same.
Check 3: leftover invisible characters
TRIM only handles the ordinary space (character code 32). A non-breaking space (code 160) survives it, so the length test above can pass while the problem remains. Search for it directly:
=COUNTIF(Clean!A2:A, "*" & CHAR(160) & "*")For other non-printing characters, test whether CLEAN would change the text:
=SUMPRODUCT(--(LEN(Clean!A2:A) <> LEN(CLEAN(Clean!A2:A))))Both checks should return 0. If either returns more, rerun the pipeline from the chapter on hidden characters: SUBSTITUTE for the non-breaking space, then CLEAN, then TRIM.
Check 4: duplicates that survived
Remove duplicates and UNIQUE compare values as they are written. Differences in spacing or case can make two copies of one record look different. Normalize first, then compare the total with the distinct count:
=COUNTA(Clean!A2:A) - COUNTUNIQUE(FILTER(LOWER(TRIM(Clean!A2:A)), Clean!A2:A <> ""))The expected result is 0. A result of 4 means four rows are repeats of earlier rows once spacing and case are ignored. The FILTER removes empty cells from the open-ended range, so blank rows are not counted as a distinct value.
If your duplicates are defined by a combination of columns (for example name plus email), build a key column such as =LOWER(TRIM(A2)) & "|" & LOWER(TRIM(B2)) and run the same test on the key. The | separator stops "ab" + "c" from matching "a" + "bc".
Check 5: split results
SPLIT and Split text to columns can misplace data without any error. Count the rows that have a value in the source column but an empty cell in the last column that should have been filled:
=COUNTIFS(Clean!A2:A, "<>", Clean!C2:C, "")Suppose names like "Doe, Jane" should become two columns. A row where the second column is empty had no delimiter in the original. A row with a value in a third column had two delimiters, so a suffix such as "Jr." or a second comma pushed data out of place. Look for a value in the column just past your expected width:
=COUNTA(Clean!D2:D)If your design allows only columns B and C, this should return 0.
The same trap applies to the delimiter itself. With =SPLIT(A2, ", ", FALSE) the two characters count as one delimiter. With the default setting, a comma and a space each split separately, which creates empty cells in the middle of your data. Check a few rows of output by eye after any change to the delimiter.
Check 6: data types
Text that looks like a number is a common leftover. A column of amounts that contains text sums to the wrong total without any error. For a column that should be entirely numeric, count the filled cells that are not numbers:
=COUNTA(Clean!D2:D) - COUNT(Clean!D2:D)The expected result is 0. REGEXREPLACE always returns text. After =REGEXREPLACE(A2, "[^0-9]", "") the phone number "5550101234" is text, which is usually right for identifiers. If you need a real number, wrap the formula in VALUE. Be aware that VALUE drops leading zeros, so never convert postal codes or account numbers.
The same idea works for dates. Dates are stored as numbers, so the formula above also catches dates that were left as text.
Check 7: errors
Formula-based cleanup can leave #N/A, #VALUE!, or #REF! in the result. Count every error in the cleaned range:
=SUMPRODUCT(--ISERROR(Clean!A2:D))The expected result is 0. Also read the error text when it appears. A #REF! from an ARRAYFORMULA(SPLIT(...)) usually means the output range is blocked by existing data, so the formula cannot expand. Clear the cells in its path.
Spot check against the raw data
Counts prove the shape is right, but they cannot prove the content is. Find what changed by comparing the raw and clean sheets. This works when the two sheets still line up row by row, meaning you have not yet removed duplicates. EXACT matters here, because the = operator ignores case and would hide case changes:
=FILTER(Raw!A2:A, NOT(EXACT(Raw!A2:A, Clean!A2:A)))The result lists every raw value that the cleanup changed. Scroll the list and look for surprises. A name that lost a character, or an entry that changed meaning, shows up here. If the list is very long, review a sample: pick ten rows at random and compare them cell by cell with the original.
For a sheet where duplicates were already removed, find the raw values that no longer appear in the clean sheet, ignoring case:
=FILTER(Raw!A2:A, Raw!A2:A <> "", ISNA(MATCH(Raw!A2:A, Clean!A2:A, 0)))Values trimmed or changed by other steps will also appear in this list, so read it as "values that are not present in exactly this form". The values that should be there are the duplicates you intended to remove. Anything else needs an explanation.
Assemble the Checks sheet
Put these results in a table so the whole cleanup can be judged at a glance:
| Check | What it measures | Expected |
|---|---|---|
| Row count difference | Raw rows minus removed duplicates minus clean rows | 0 |
| Leftover spaces | Cells where LEN differs from LEN of TRIM | 0 |
| Non-breaking spaces | Cells containing CHAR(160) | 0 |
| Surviving duplicates | Total rows minus distinct normalized rows | 0 |
| Overflow columns | Values past the expected split width | 0 |
| Non-numeric cells | Text in a numeric column | 0 |
| Errors | Cells showing any error | 0 |
Add a final cell that combines them, for example =IF(SUM(B2:B8)=0, "PASS", "REVIEW"). A PASS only means the automated checks found nothing, and the spot check still has to be done by a person.
Common mistakes
- Checking only one column. Dirty data hides in the columns you did not look at. Repeat each check per text column.
- Trusting the tool's confirmation message. "30 duplicate rows removed" says nothing about the duplicates it missed.
- Using
=to compare text. It ignores case, so case changes look like no change. Use EXACT. - Deleting the raw sheet. Without it, nothing above can be done. Keep it until the data has been used successfully downstream.
- Cleaning in place and checking afterward. The checks need a before and an after.
Exercise
Your Raw sheet has 1,200 data rows. The COUNTIF flag column marks 85 rows as repeats, and you removed them. Clean now has 1,120 rows. Which check reveals a problem, and what is a likely cause?
Show answer
The row count check. The expected clean count is 1,200 - 85 = 1,115, so Clean has 5 extra rows. The most likely cause is repeats that differ only by invisible characters, such as a non-breaking space, or by case or spacing, so the cleanup did not treat them as matches. Run the surviving-duplicates check (COUNTA minus COUNTUNIQUE of the lowercased, trimmed values) and the CHAR(160) COUNTIF to confirm.
Exercise
Column A of Clean holds full names, and you split them into columns B and C. Write one formula that counts rows where A has a value but C is empty. Then say what a nonzero result means.
Show answer
=COUNTIFS(Clean!A2:A, "<>", Clean!C2:C, "") A nonzero result means that many rows were not split into two parts. Their original value had no delimiter (for example a single name), or the delimiter differed from the one you used. Inspect those rows and decide whether to fix the source or handle them separately.