Cleaning an export by hand works once. The next export arrives with the same problems in a different order, and the work starts again. The aim is a set of rules that runs every time new data lands, so whoever opens the workbook sees clean figures without repeating the fixes.
Automatic cleaning rests on three conditions. The raw data stays untouched, every fix is a formula or a recorded query step, and the output updates when the input changes. If those hold, the specific tool matters less than you might expect.
What automatic cleaning does and does not do
Automatic cleaning removes stray spaces, converts text that looks like numbers or dates into real values, standardises labels, drops blank and duplicate rows, and flags anything it cannot fix. It does not decide what the data means. If a column holds “NW” in one export and “North West” in the next, a rule can map both to one label, but a person has to write that mapping and keep it current.
Expect the automation to handle the predictable 90 per cent or so of problems. The remainder needs a flag, not a silent guess. A cleaning process that quietly turns an unreadable amount into zero is worse than no process at all.

Skip the setup
BalanceBloom Bookkeeping Studio
Income, expenses, profit and loss and sales tax in one bookkeeping workbook for Excel and Google Sheets.
Glossary of terms used in this guide
- Raw tab: the untouched export. Nothing is typed or edited here.
- Clean tab: the output, built only from formulas or queries that read the raw tab.
- Helper column: a formula column that prepares a value for a later step.
- Cleaning SOP: the written, ordered set of rules the workflow follows. Keep it in a notes tab inside the workbook, with the date of each change.
- Refresh: re-running the rules against the current raw data.
- Non-breaking space: character code 160. It looks like a space, but TRIM does not remove it.
- Locale: the regional setting that decides how dates and decimal separators are read. The same text can mean different dates in different locales.
- Query step: one recorded action in Power Query, such as trimming a column or changing its type.
Diagnose the imported data before writing any rule
Profile the export before you build anything. Open a copy and check each column for three kinds of problem. Count the problems in each column, because the count shows which method is worth the effort.
Hidden characters
Hidden characters are the most common reason a formula appears to work but does not. Test a suspicious cell with =LEN(A2) and compare the result with the visible character count. A name that reads “Smith” but returns 7 has two hidden characters.
The usual culprits are non-breaking spaces copied from web pages and some accounting systems, line breaks inside a cell (character 10), and a byte order mark at the start of a CSV file, which shifts the first header name. A stray “” before a pound sign means the file was saved in one encoding and opened in another.
Numbers and dates stored as text
A value is text if =ISTEXT(B2) returns TRUE. Sums and sorts skip text silently, so a column of amounts such as “£1,240.50” can total to zero without any error message.
Dates stored as dd/mm/yyyy text are a particular risk. A spreadsheet set to a US locale may read 03/04/2025 as 4 March rather than 3 April. Negative amounts often arrive in brackets, so “(250.00)” means minus 250. Check for these patterns in every amount column.
Structural problems
Structural problems break any formula that assumes a clean rectangle of data. Look for blank rows between blocks, a header repeated on each page of a PDF-derived export, merged cells, a totals row sitting inside the data, and footnotes below the table.
Write the counts down. An export with three problem columns out of twelve suits helper formulas. An export with dozens of structural quirks that change every month suits a query.
Choose the right method
The three main approaches differ in where they run, how they refresh and how much structural change they tolerate.
| Approach | Where it runs | When it refreshes | Handles structural problems | Skill needed | Best suited to |
|---|---|---|---|---|---|
| Helper-column formulas | Any spreadsheet | As soon as the raw data changes | Weak, breaks if the layout shifts | Basic to moderate | Stable layouts, modest row counts |
| Power Query | Excel for Windows and Microsoft 365, with more limited support on Mac | On Refresh All, or on open if set | Strong: removes rows, unpivots, filters | Moderate | Recurring file drops with variable structure |
| Apps Script | Google Sheets | On a time-driven or edit trigger | Strong, but only as good as the code | Moderate to high | Google Sheets workflows needing scheduled runs |
Check which version of Excel you have before committing to Power Query, since support differs between Windows, Mac and older builds. Google Sheets has no Power Query, and its built-in Data cleanup menu (Trim whitespace, Remove duplicates) is a one-off action, not an automated one.
Helper-column formulas
Here the rules sit beside the raw data. Each clean column refers to one raw column, so an auditor can click any cell and read the rule. That transparency is the main strength.
The weakness is layout drift. If the export inserts a column in the middle, fixed references point at the wrong data. Pull columns by header name with MATCH or XLOOKUP where possible, and keep a check that the expected headers are still in place.
Power Query
Power Query records each step (Trim, Replace Values, Change Type, Remove Rows) and replays them in order on every refresh. Drop a new export into the source folder, click Refresh All, and the full cleaning runs again.
For dates in dd/mm/yyyy text, use Change Type with Locale and choose English (United Kingdom) so that day and month are read correctly. Power Query also handles unpivoting and removing repeated header rows, which formulas handle poorly. The cost is a longer first build and a learning curve for the people who maintain it.
Apps Script
A script reads the raw tab, applies the rules and writes to the clean tab. A time-driven trigger can run it hourly or daily, and an edit trigger can run it when the raw tab changes.
The costs are build time and maintenance. Someone must own the script when it breaks, and quotas limit how long scripts can run each day and how many triggers an account can hold. Workspace accounts usually get higher limits than personal accounts. Use Apps Script when a schedule or a Google-only process requires it, not as a default.
Build the cleaning workflow step by step
Follow this sequence whichever method you choose. The order matters, because each step depends on the one before.
- Store each export on the raw tab, unedited. Paste the new file over the old one, or into a dated raw tab if you need history.
- Profile the columns. Check
LEN,ISTEXTand blank counts for each field, and record the results in the cleaning SOP. - Write one rule per problem, in this order: remove hidden characters, trim, convert types, standardise labels, handle negatives, then drop structural rows.
- Place every rule in a helper column or a query step. Never type over the raw tab.
- Add validation: compare row counts in and out, compare totals before and after cleaning, and count any unmapped labels.
- Automate the refresh with an Excel Table, a Power Query refresh or an Apps Script trigger.
- Update the cleaning SOP with the date and the reason for every change to a rule.
Ready-made template
Tagtally Reseller Profit Tracker
Log every item, platform fee and shipping cost, and see your real profit per sale without doing the maths.
Worked example: cleaning a monthly sales export
The example below uses a sales export that arrives each month with five columns: Order ID, Customer, Order Date, Amount and Country. Order Date is dd/mm/yyyy text. Amounts are text with a pound sign and thousands separators, and negatives appear in brackets. Country uses three spellings for the same market (“UK”, “U.K.”, “United Kingdom”). Some customer names contain non-breaking spaces. The export has blank rows between sections and a totals row at the bottom.
The raw tab
The raw tab holds the export exactly as received. Nothing is edited there. The clean tab, called CLEAN, reads from it, and a mapping tab, called MAP, holds two columns: the raw label in column A and the standard label in column B.
The formulas
In Google Sheets, the following formulas on the CLEAN tab cover each column. Each one uses ARRAYFORMULA, so it fills down automatically as new rows arrive.
Customer names, with non-breaking spaces replaced and extra spaces removed:
=ARRAYFORMULA(IF(RAW!B2:B="","",TRIM(SUBSTITUTE(RAW!B2:B,CHAR(160)," "))))
Order date, converted from dd/mm/yyyy text to a true date:
=ARRAYFORMULA(IF(RAW!C2:C="","",DATE(VALUE(RIGHT(RAW!C2:C,4)),VALUE(MID(RAW!C2:C,4,2)),VALUE(LEFT(RAW!C2:C,2)))))
Amount, with the pound sign, commas and brackets removed, and brackets treated as negatives:
=ARRAYFORMULA(IF(RAW!D2:D="","",IF(LEFT(RAW!D2:D,1)="(",-1,1)*VALUE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(RAW!D2:D,"£",""),",",""),"(",""),")",""))))
So “(250.00)” becomes -250, and “£1,240.50” becomes 1240.5.
Country, mapped through the MAP tab:
=ARRAYFORMULA(IF(RAW!E2:E="","",IFERROR(VLOOKUP(TRIM(RAW!E2:E),MAP!A:B,2,FALSE),"UNMAPPED")))
In Excel 365, the equivalent is =IFERROR(XLOOKUP(TRIM(RAW!E2),MAP!A:A,MAP!B:B),"UNMAPPED") filled down the table. Note that the flag is a visible word, not a zero or a blank.
Removing blank rows and the totals row: wrap the output in a filter that keeps rows with an Order ID and a parsed date. The totals row has no Order ID, so it drops out. In Sheets, that is =FILTER(...,RAW!A2:A<>"", ISNUMBER(...)) around the output range, or an equivalent QUERY call.
Validation
Three checks catch most failures:
- Row count: the number of non-blank Order IDs on RAW, minus the totals row, should equal the number of rows on CLEAN.
- Totals: the sum of amounts on CLEAN should match the total on the export’s own totals row, within rounding.
- Mapping:
=COUNTIF(CLEAN!E:E,"UNMAPPED")should return 0. Any other number means a new spelling has appeared and the MAP tab needs a new line.
Making it run on its own
Paste each month’s export over the raw tab, and the clean tab updates through the formulas. No button is pressed. If the export arrives as a file in a folder, Power Query can perform the same steps, with a refresh on open. In Apps Script, a daily time trigger can copy the file in and run the check.
Keep the formulas on a separate tab from the raw data. A paste that overwrites the wrong range should destroy the raw export, not the logic.
Common mistakes and how to avoid them
- Trusting TRIM to clean everything. TRIM does not remove non-breaking spaces. Replace character 160 first, then trim.
- Cleaning on the raw tab. The next export overwrites the work, and there is no audit trail. Keep formulas and raw data apart.
- Converting dates before setting the locale. A date that converts correctly in one locale can silently convert wrongly in another. Set the locale explicitly.
- Using fixed ranges. A formula that stops at row 500 will ignore row 501 without warning. Use open-ended references or Excel Tables.
- Hiding errors with a zero.
IFERROR(..., 0)turns a failed conversion into a plausible-looking number. Use a visible flag such as “UNMAPPED” or “CHECK”. - Losing leading zeros. A postcode or product code such as “01234” becomes 1234 when opened as a number. Set the column to text before import, or import it through Power Query with the type set to text.
- Skipping validation after upstream changes. When the source system changes its export, the rules may still run without error and produce wrong results. Re-run the checks after any change upstream.
Costs, trade-offs and limits
Each method has a different cost profile, and the cheapest one to build is not always the cheapest to run.
Helper-column formulas take an afternoon to build for a stable export and are easy to audit. They become expensive when the layout changes, because someone must find and fix each broken reference by hand. They also slow down with very large row counts, since every helper column recalculates on each change.
Power Query takes longer to build the first time and tolerates layout drift better. Its refresh is fast for typical monthly files, though the speed depends on file size and the number of steps. It needs a version of Excel that supports it, and a colleague who works in Google Sheets cannot open the query at all.
Apps Script adds a maintenance owner. Someone must read the code, know what the triggers do and respond when a quota is hit. For a single person’s monthly export, that overhead is rarely justified. For a shared team process that must run without anyone opening the file, it can be the right choice.
Cost also includes the checks. A method with no validation is cheap to build and expensive when it fails quietly. Budget time for the validation steps in every option.
A decision rule to finish with
If the layout is stable, the row count is modest and the people who maintain the file are comfortable with formulas, use helper columns on a clean tab. If the layout changes, the file arrives as a recurring CSV or Excel drop, or the cleaning involves unpivoting or repeated headers, use Power Query. Use Apps Script only when a schedule or a Google-only process requires it, and name the person who owns it before you build it.
Whichever method you pick, the checklist is the same:
- The raw tab is never edited.
- Each rule is written down in the cleaning SOP, in order, with its date.
- Unmapped or unconvertible values show as a visible flag.
- Row counts and totals are compared before and after every refresh.
- A named owner reviews the rules when the source system changes.