Sub topic 9
Checking and cleaning the imported data
An import that finishes without an error message can still contain wrong data. Google Sheets converts text to numbers, dates and formulas on its own, so a file can arrive with missing rows, numbers stored as text, shifted dates or invisible spaces. This chapter gives you a repeatable way to check an import and fix what it got wrong.
It assumes you have already imported a file with File > Import or opened one from Drive, and that you know basic formulas such as TRIM and TEXT. Everything here works on data that is already in a sheet.
Keep the raw import untouched
Do your cleaning on a copy, not on the imported cells. If a cleaning formula goes wrong, you need the original to compare against and to start over from.
A reliable layout uses two sheets:
- A raw sheet named
Raw, holding exactly what the import produced. Do not edit it. - A clean sheet named
Clean, whose formulas read fromRawand fix its values.
Once you are happy with Clean, you can freeze it into plain values (see the end of this chapter). If you import the same file again later, you replace Raw and the Clean sheet updates itself.
The checking workflow
Check in the same order each time. Cheap checks come first, because they find the biggest problems.
Structural problems (wrong separator, wrong encoding, missing rows) are fixed by importing again with different settings, not by formulas. Content problems (types, spaces, duplicates) are fixed in the sheet. That is why the structure check comes first.
Check 1: row and column counts
Compare the sheet with the source file. For a CSV, open the file in a text editor to see the number of lines. Then count the non-empty cells in a column that is always filled, such as an ID:
=COUNTA(A2:A)Add 1 for the header row and compare the result with the line count of the file. Three results are common:
- The counts match. Rows survived.
- The sheet has fewer rows. Some quoted fields may contain line breaks, or the file may have trailing blank lines. Check the last few rows by eye. A text editor may also count a multi-line field as several lines.
- Everything is in column A. The separator was wrong. Re-import with the correct separator type.
Check the width too. Scan the header row. If you see header names glued together, such as id;name;city in one cell, the separator is wrong. If you see extra empty columns on the right, some rows contain more delimiters than the header.
Check 2: the type of each column
Sheets stores every cell as a number, a date, text, or a boolean. Imports often get this wrong for individual columns. The fastest visual check is alignment. By default, numbers and dates align right and text aligns left. A column of amounts that is left-aligned holds text.
The formula check is more reliable. COUNT counts only numeric cells (dates are numbers too). COUNTA counts all non-empty cells. In a column that should be numeric, the two must match:
=COUNTA(C2:C)-COUNT(C2:C)A result of 0 means every value is a number. Any other result is the number of cells stored as text. To see which cells they are:
=FILTER(A2:C, ISTEXT(C2:C))This returns the whole rows whose column C value is text. If every row in the column is text, FILTER returns all of them. If none are, it shows an error saying no matches were found, which is the good outcome here.
Numbers stored as text
The usual causes are thousands separators, currency symbols, or a locale that uses a comma as the decimal mark. Strip the symbols and convert with VALUE:
=ARRAYFORMULA(VALUE(SUBSTITUTE(SUBSTITUTE(C2:C, "$", ""), ",", "")))This formula suits a US-style value such as $1,234.50. For European-style text such as 1.234,56 in a spreadsheet with a US locale, swap the roles of the two characters:
=ARRAYFORMULA(VALUE(SUBSTITUTE(SUBSTITUTE(C2:C, ".", ""), ",", ".")))Check the spreadsheet locale under File > Settings before you choose. The locale decides which decimal mark VALUE expects. If the locale itself is wrong for the file, changing it and re-importing is simpler than converting every column.
Dates that are text or are wrong
Dates have two failure modes. They arrive as text, so sorting and date arithmetic fail. Or they arrive as real dates with day and month swapped, which is worse because nothing looks broken.
Test for the first one with COUNT as above. Test for the second one by looking for impossible values. A day value above 12 can never be a month, so a file in day-first format imported into a month-first locale leaves some dates as text and turns others into the wrong date. A mix of left-aligned and right-aligned values in a date column is the sign.
Convert unambiguous text dates with DATEVALUE, or build the date yourself when you know the format. For day-first text like 28.11.2026:
=ARRAYFORMULA(IF(D2:D="", "", DATE(RIGHT(D2:D, 4), MID(D2:D, 4, 2), LEFT(D2:D, 2))))After that, format the column as a date with Format > Number > Date, or the result displays as a serial number such as 46354.
Leading zeros
A ZIP code, a product code or a phone number that lost its leading zeros was converted to a number. If the codes have a fixed length, restore them with TEXT:
=TEXT(A2, "00000")This pads 2134 to 02134. The result is text, which is what you want for an identifier. It does not help when the length varies, and it would mislead if some codes legitimately have more digits (for example ZIP+4 codes). For those, re-import with automatic conversion switched off, so the codes never become numbers.
Check 3: whitespace and duplicates
Extra spaces
Leading, trailing and doubled spaces make two visually identical values compare as different. Lookups with VLOOKUP or MATCH then fail without any error that explains why. TRIM removes leading and trailing spaces and reduces runs of spaces to one:
=ARRAYFORMULA(TRIM(A2:A))TRIM does not remove the non-breaking space (character 160), which often arrives in files exported from web pages and some Excel sheets. If TRIM seems to do nothing, replace that character first, and remove other non-printing characters with CLEAN:
=ARRAYFORMULA(TRIM(CLEAN(SUBSTITUTE(A2:A, CHAR(160), " "))))To find out whether a cell has hidden characters, compare lengths. If LEN(A2) differs from LEN(TRIM(A2)), the cell has extra spaces. For a quick count over a whole column:
=SUMPRODUCT(LEN(A2:A) <> LEN(TRIM(A2:A)))The menu route is Data > Data cleanup > Trim whitespace. It edits the cells in place, so use it on a copy, not on Raw.
Duplicates
Duplicate rows appear when a file was exported twice or two files were appended into one sheet. First find them without deleting anything. Highlight them with a conditional-formatting rule (Format > Conditional formatting, custom formula) on the ID column:
=COUNTIF($A$2:$A, $A2) > 1Review the highlighted rows. Two rows with the same ID but different amounts are a data problem, not a harmless duplicate, and deleting one loses information. When the duplicates are exact copies, use Data > Data cleanup > Remove duplicates, and choose the columns that define "the same row". To build a de-duplicated list without altering the original, use =UNIQUE(A2:D) on the clean sheet.
Do the trim step before the duplicate step. "Smith" and "Smith " are different values until you trim them, so duplicates would go unnoticed.
Check 4: spot-check against the source
Formulas catch type and structure problems. They cannot tell you that a value is wrong but well-formed. Finish with a manual comparison.
- Pick 5 to 10 rows: the first, the last, and a few in between, including any row with unusual characters or long text.
- Open the same rows in the source file and compare every field.
- Compare a total. Add up a numeric column in the sheet and in the source (Excel shows a sum in its status bar). A difference points to numbers converted wrongly or rows lost.
- Look at the longest text values. A cell cut off at a line break or a quote mark signals a quoting problem in the file.
Garbled characters such as é where é should be are an encoding problem. No cleaning formula fixes them reliably. Import the file again with the correct encoding instead.
Cleaning at a glance
| Symptom | Likely cause | Check | Fix |
|---|---|---|---|
| All data in column A | Wrong separator | Look at the header row | Re-import with the right separator |
| Amount column is left-aligned | Numbers stored as text | `COUNTA` minus `COUNT` | `VALUE` with `SUBSTITUTE` |
| Codes lost leading zeros | Converted to numbers | Compare with the source | `TEXT(A2, "00000")` or re-import without conversion |
| Lookups fail on matching values | Extra or non-breaking spaces | `LEN` versus `LEN(TRIM())` | `TRIM(SUBSTITUTE(...CHAR(160)...))` |
| Some dates are text | Locale mismatch | `COUNT` on the date column | Rebuild with `DATE`, or change locale and re-import |
| Accented letters garbled | Wrong encoding | Visual check | Re-import with the right encoding |
Freezing the clean data
Formulas in Clean depend on Raw. If you delete Raw or move columns in it, the results break. When you are finished, convert the results to fixed values:
- Select the clean range.
- Copy it with Ctrl+C (Cmd+C on a Mac).
- Paste with Edit > Paste special > Values only, or Ctrl+Shift+V.
- Delete the
Rawsheet only when you are sure you no longer need to compare with it.
Keep a note of which fixes you applied, for example in a cell on the first sheet. Someone who imports the next version of the file will have to repeat them.
Exercise
A column of order totals imported as 1.234,56 style text into a spreadsheet whose locale is United States. =COUNTA(C2:C)-COUNT(C2:C) returns 480, and 480 is also the number of data rows. Write a formula that converts the whole column into real numbers, and explain how you would confirm that it worked.
Show answer
Use =ARRAYFORMULA(VALUE(SUBSTITUTE(SUBSTITUTE(C2:C, ".", ""), ",", "."))). The inner SUBSTITUTE removes the thousands dots, and the outer one turns the decimal comma into a decimal point, which a US locale expects. To confirm, run =COUNT(range) on the result column, which should return 480, and compare the sum of the column with the total in the source file. The converted values should also be right-aligned.
Exercise
Two rows in a customer sheet both read "Maria Lopez", yet =COUNTIF(A2:A, A2) > 1 does not flag them. TRIM on the cells changes nothing. What is the most likely cause, and which formula fixes it?
Show answer
At least one cell most likely contains a non-breaking space (CHAR(160)), which TRIM does not remove. Use =ARRAYFORMULA(TRIM(CLEAN(SUBSTITUTE(A2:A, CHAR(160), " ")))) on the clean sheet, then run the duplicate check on the cleaned column. You can confirm the cause by comparing LEN of the two cells: they differ even though the text looks the same.