The firm opens soon. Guides and calculators are already free to use —get notified when we open
Excel

Excel: cleaning data exported from software (spaces, text amounts, dates, duplicates)

Stray spaces, amounts stored as text, unrecognised dates, duplicates: TRIM, SUBSTITUTE, VALUE, DATE and Remove Duplicates. Illustrated Excel tutorial.

Published 10 min readLevel: BeginnerEl Arabi Aich

In brief
  • Software exports almost always contain stray spaces, numbers stored as text, unrecognised dates and duplicates that break formulas.
  • Basic functions are enough: TRIM, SUBSTITUTE, VALUE, DATEVALUE, PROPER, LEFT/RIGHT/MID, plus Data > Remove Duplicates.
  • The core rule: never overwrite raw data; build cleaned columns alongside, then paste them as values.
  • For recurring imports, Power Query records the cleaning steps and replays them on each refresh.

Your payroll or invoicing software exports an Excel file. You sum a column: zero. You run a lookup: #N/A. The same causes recur from one file to the next: invisible spaces, amounts stored as text, unrecognised dates, and duplicates. This tutorial sets out the method and formulas to clean an export in a few minutes.

Golden rule: never touch the raw data

Keep the imported sheet intact. Create cleaning columns to the right, check them, then paste as values. If a mistake happens, you can start again without re-exporting.

The four most common defects

Defect Symptom Function
Stray spaces A lookup fails to find “Invoice F-0231” TRIM
Amount stored as text Left-aligned, zero sum VALUE, SUBSTITUTE
Date stored as text Alphabetical sort, unable to group by month DATE, DATEVALUE
Duplicates Inflated totals Data > Remove Duplicates

Cleaning spaces

TRIM removes leading and trailing spaces and reduces multiple spaces between words to a single space:

=TRIM(B2)

If the text contains a non-breaking space (common in web exports):

=TRIM(SUBSTITUTE(B2,CHAR(160)," "))

To standardise letter case: =PROPER(TRIM(B2)) capitalises each word (“Transfer CLIENT alpha” becomes “Transfer Client Alpha”). UPPER and LOWER are also available.

Converting a text amount into a number

An amount imported as 12 450,00 (with a space thousands separator and decimal comma) is text. Strip the spaces and, depending on your regional settings, replace the comma:

=VALUE(SUBSTITUTE(SUBSTITUTE(C2," ",""),",","."))

Data imported from software with stray spaces and text amounts on the left, cleaned result on the right using TRIM, SUBSTITUTE and VALUE Figure 1: raw data on the left (marker 1), converted amount (marker 2) and cleaned description (marker 3) on the right. (Note: the illustration shows the French-language Excel interface and function names—SUPPRESPACE, SUBSTITUE, CNUM, ;—while all formulas and menu paths in the text use English Excel syntax.)

Adapt according to whether your Excel uses a comma or a period as the decimal separator: in an English-locale Excel using a period, replace the comma with . as shown above; in a French-locale configuration where the comma is already the decimal separator, =VALUE(SUBSTITUTE(C2," ","")) is enough.

Quick alternative without formulas: select the column > Data > Text to Columns > Finish. Excel re-parses the contents and recognises them as numbers (according to your regional settings).

Converting a text date

For 2026-03-05 (ISO format):

=DATE(LEFT(A2,4),MID(A2,6,2),RIGHT(A2,2))

LEFT extracts the year, MID extracts the month (starting at the 6th character), and RIGHT extracts the day. Then apply the date format you want. For 05/03/2026 received as text with a different separator, the same logic applies by extracting each of the three parts. DATEVALUE directly converts any text date recognised by your regional settings.

Extracting part of a text string

For a description such as 6111 - Purchases of goods:

Need Formula
Account number =LEFT(A2,4)
Description only =RIGHT(A2,LEN(A2)-7)
Text after a hyphen =MID(A2,FIND("-",A2)+2,100)
Split into columns without formulas Data > Text to Columns (delimited by -)

Amount formats you will encounter

Exports vary widely. Here are the most frequent formats and the formula that handles them (source cell in C2, assuming an English-locale Excel using . as the decimal point):

Format in export Example Formula
Standard space thousands separator 12 450,00 =VALUE(SUBSTITUTE(SUBSTITUTE(C2," ",""),",","."))
Non-breaking space 12 450,00 (character 160) =VALUE(SUBSTITUTE(SUBSTITUTE(C2,CHAR(160),""),",","."))
Narrow non-breaking space (recent exports) 12 450,00 (character 8239) =VALUE(SUBSTITUTE(SUBSTITUTE(C2,UNICHAR(8239),""),",","."))
Currency suffix 12450,00 DH =VALUE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(C2," DH","")," ",""),",","."))
Negative in parentheses (1 250,00) =-VALUE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(C2,"(",""),")","")," ",""),",","."))
Trailing minus sign 1250,00- =IF(RIGHT(C2,1)="-",-VALUE(SUBSTITUTE(LEFT(C2,LEN(C2)-1),",",".")),VALUE(SUBSTITUTE(C2,",",".")))
Period as decimal separator 12450.00 =VALUE(C2) (or =VALUE(SUBSTITUTE(C2,".",",")) in a French-locale Excel)

To handle several cases in a single file, nest SUBSTITUTE calls: =VALUE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(C2," ",""),CHAR(160),""),UNICHAR(8239),""),",",".")).

A complete five-row exercise

A supplier general ledger export, before cleaning:

Account Description Amount Date
4411 invoice alpha LLC (SARL) 12 450,00 2026-03-05
4411 INVOICE BETA (3 200,00) 2026-03-07
4411 invoice gamma 8 000,00 2026-03-07
4411 invoice gamma 8 000,00 2026-03-07
4417 Accrued delta 5 500,00 2026-03-31

After cleaning (columns to the right, then pasted as values):

Account Cleaned description Amount (number) Date (true date) Note
4411 Invoice Alpha Llc (Sarl) 12,450.00 05/03/2026 Spaces fixed
4411 Invoice Beta −3,200.00 07/03/2026 Negative converted
4411 Invoice Gamma 8,000.00 07/03/2026 Duplicate to inspect
4411 Invoice Gamma 8,000.00 07/03/2026 Same invoice entered twice?
4417 Accrued Delta 5,500.00 31/03/2026 Unbilled invoice accrual

Formulas used: =TRIM(A2) for the account, =PROPER(TRIM(B2)) for the description, the parentheses formula for the negative amount, and =DATE(LEFT(D2,4),MID(D2,6,2),RIGHT(D2,2)) for the date. The two “Gamma” rows are flagged by =COUNTIFS($B$2:$B$6,B2,$C$2:$C$6,C2,$D$2:$D$6,D2)>1: always check before deleting, because two legitimate invoices can have the same amount on the same day.

Control check: sum of cleaned amounts = 12,450 − 3,200 + 8,000 + 8,000 + 5,500 = 30,750; the source software must show the same total (net of the negative entry).

Power Query step by step

For a monthly import, the recommended approach is Power Query. Its steps are visible in the Advanced Editor; here is the equivalent of the cleaning above (adapt the path and column names):

let
    Source = Excel.Workbook(File.Contents("C:\Imports\general-ledger.xlsx"), null, true),
    Sheet = Source{[Item = "Suppliers", Kind = "Sheet"]}[Data],
    Headers = Table.PromoteHeaders(Sheet, [PromoteAllScalars = true]),
    Descriptions = Table.TransformColumns(Headers, {{"Description", Text.Trim, type text}, {"Account", Text.Trim, type text}}),
    Types = Table.TransformColumnTypes(Descriptions, {{"Amount", type number}, {"Date", type date}}, "fr-FR"),
    NoDuplicates = Table.Distinct(Types, {"Description", "Amount", "Date"})
in
    NoDuplicates

In the user interface, the same steps are performed by clicking: Data > Get Data > From File, then Transform Data: promote the first row to headers, Format > Trim, set column data types using Using Locale (France) when the source uses French number/date formatting, and Remove Duplicates on the chosen columns. Each month, simply replace the source file and click Refresh All.

Note: Table.Distinct removes duplicates silently here without showing them first. To inspect them beforehand, add a grouping count column (Group By) or load the cleaned output and the duplicate list into two separate sheets.

Removing duplicates

Select the range > Data > Remove Duplicates > tick the columns that define a duplicate (for example Invoice No. + Amount). Warning: this action is permanent; work on a copy. To spot duplicates without deleting them, use Conditional Formatting > Duplicate Values, or =COUNTIF($A$2:$A$500,A2)>1.

Handling errors

Error Cause Solution
#VALUE! Unconvertible text (letters inside an amount) IFERROR(VALUE(...),0) and visual check
#N/A Value missing from lookup table Clean the lookup keys, IFERROR
### Column too narrow Widen the column
Result 0 Number stored as text VALUE or Text to Columns

Moving towards automation: Power Query

For recurring monthly imports (trial balance, bank statement), Power Query (Data tab > Get Data) records every cleaning step: trimming spaces, changing data types, filtering, renaming. On the next import, clicking Refresh replays everything. No formulas to drag down, and thousands of rows are processed without slowing down the workbook.

Ten dirty-data cases and the formula that fixes them

Here is a catalogue of defects found in software, bank and customer file exports, with the formula (in cell B2, raw data in A2) that cleans them.

Raw data (A2) Problem Cleaning formula Result
Atlas Distribution Extra spaces =TRIM(A2) Atlas Distribution
ATLAS distribution Inconsistent casing =PROPER(TRIM(A2)) Atlas Distribution
12 345,50 (text) Text amount with non-breaking space =VALUE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A2,CHAR(160),"")," ",""),",",".")) 12345.5
12.345,50 Period thousands separator =VALUE(SUBSTITUTE(SUBSTITUTE(A2,".",""),",",".")) 12345.5
(1 250,00) Negative in parentheses =-VALUE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A2,"(",""),")","")," ",""),",",".")) −1250
2026-03-14 or 14/03/2026 as text Date stored as text =DATEVALUE(A2) or =DATE(RIGHT(A2,4),MID(A2,4,2),LEFT(A2,2)) 14/03/2026
5141 (number) and "5141" (text) Mixed data types =TEXT(A2,"0") 5141
0001234 Leading zeros lost =TEXT(A2,"0000000") 0001234
RIB 007 780 0001234567890123 45 Spaces inside an identifier =SUBSTITUTE(A2," ","") RIB without spaces
Invoice no. F-2026-014 / Atlas Multiple pieces of info in one cell =MID(A2,FIND("F-",A2),10) F-2026-014

Enter each formula in a column next to the raw data, then copy and paste values into the working sheet. The raw data remains intact, allowing you to redo or audit the cleaning.

Combining multiple files with Power Query

Suppose a folder holds twelve monthly statements (CSV) with the same structure. Power Query combines them automatically:

  1. Data > Get Data > From File > From Folder, and choose the folder.
  2. Combine > Combine & Transform Data: Power Query uses the first file as a template and applies the same steps to the others.
  3. In the editor: Use First Row as Headers, set each column’s data type (date, text, decimal number with French locale if the source uses decimal commas), and remove blank rows and intermediate subtotals.
  4. Split Column on any composite column (by delimiter) and Remove Duplicates.
  5. Close & Load into an Excel Table.

Whenever a new statement is placed in the folder, Data > Refresh All updates the table. A file that took three hours manually each month takes three minutes.

Consistency checks after cleaning

Check Formula Expected
Raw row count = cleaned row count =COUNTA(Raw[Description])-COUNTA(Clean[Description]) 0
Total debits and credits identical before and after =SUM(Raw[Amount])-SUM(Clean[Amount]) 0
No unconverted date cells =COUNTIF(Clean[Date],"") or ISNUMBER check 0
No duplicate keys =COUNTIFS(Clean[Number],Clean[@Number],Clean[Date],Clean[@Date])>1 FALSE everywhere
Dates within the financial year =AND(Clean[@Date]>=StartDate,Clean[@Date]<=EndDate) TRUE everywhere
Accounts present in chart of accounts =COUNTIF(ChartOfAccounts[Account],Clean[@Account])=1 TRUE everywhere

These checks take one minute and prevent importing a file into accounting that would introduce an imbalance.

Preparing an accounting import file

Many accounting packages accept journal entry imports from a CSV or Excel file. The file must follow a strict structure:

Column Content Rule
Date Entry date dd/mm/yyyy format, within the open financial year
Journal Journal code Must exist in the software
Account Account number Text, must exist in the chart of accounts
Description Narrative No line breaks
Ref Supporting document reference Mandatory
Debit Debit amount Number, dot or comma depending on the software
Credit Credit amount Same

The most important constraint: every entry must be balanced (total debit = total credit). A check column =SUMIF(Ref,[@Ref],Debit)-SUMIF(Ref,[@Ref],Credit) verifies balance by document reference. Before final import, always run a test on a backup copy of the database or a test financial year.

Post-cleaning checks

  1. The row count before/after is consistent (excluding removed duplicates).
  2. The sum of cleaned amounts matches the source software.
  3. No error cells (COUNTIFS checking ISERROR).
  4. Dates sort chronologically and fall within the right period.
  5. Lookup keys find their expected matches.

Quick-reference sheet: the ten cleaning functions

Function Purpose
TRIM Remove extra spaces
PROPER, UPPER, LOWER Standardise letter case
SUBSTITUTE Replace a character (remove periods, replace non-breaking spaces)
VALUE Convert text into a number
DATEVALUE or DATE Convert text into a date
TEXT Enforce a format (leading zeros, accounts as text)
LEFT, RIGHT, MID Extract part of a text string
FIND Locate the position of a separator
COUNTIFS Detect duplicates
IFERROR Handle conversion errors

Five habits to keep:

  • Never modify raw data: work in adjacent columns.
  • Check totals before and after cleaning.
  • Automate recurring imports with Power Query.
  • Document every step in a notes tab.
  • Test on a copy before importing into accounting.

Special cases and edge situations

The file contains garbled special characters (broken accents). CSV imports must specify the file encoding (UTF-8 or ANSI); Power Query lets you choose the File Origin explicitly.

Amounts contain currency symbols (“MAD”, “DH”). Strip the symbol with SUBSTITUTE before VALUE; use a separate currency column if multiple currencies appear.

Descriptions are truncated by the exporting software. Retrieve the full field at source rather than trying to reconstruct it; a truncated description in an accounting record risks misposting.

Subtotal rows are mixed into the data. Filter them out with a test column (=NOT(ISTEXT(...))) or in Power Query before any calculation.

Several people clean the same file. Centralise the rules in a single shared Power Query to guarantee identical results every time.

Summary

Keep raw data intact, clean in adjacent columns, verify totals before and after, automate recurring imports with Power Query, document the steps and test on a copy before any accounting import.

Frequently asked questions

How can I tell if a number is stored as text?

It aligns to the left by default, a small green triangle appears in the cell, and the formula =ISNUMBER(A2) returns FALSE. The column total stays at zero or ignores those cells.

The non-breaking space resists TRIM. What should I do?

Web exports and some software packages use a non-breaking space (character 160). Replace it first: =SUBSTITUTE(A2,CHAR(160)," ") then apply TRIM.

My dates are read in US format. How do I convert them?

If the text looks like 2026-03-05, =DATE(LEFT(A2,4),MID(A2,6,2),RIGHT(A2,2)) builds a true date. For 05/03/2026 treated as text, use DATEVALUE after reordering the parts if needed.

Should I keep the cleaning formulas?

For a one-off file, copy the cleaned columns and paste them as values (Paste Special > Values), then delete the raw columns. For a repeated import, keep the formulas or, better still, use Power Query.

El Arabi Aich

Article written from the official texts and the firm’s engagement practice. It shows its publication date and, where applicable, its last review.

Related articles

A question about your situation?

Tell us about your project: we reply within 48 business hours with a draft engagement letter.