Start free

Excel data cleaning interview question

Works in TEXTBEFORE and TEXTAFTER: Excel 365, 2024 and Excel for the web; TRIM, LEFT, MID, FIND, VALUE and DATE: every version

Key takeaways

  • Clean with formulas in a new column, never by retyping: the steps repeat on next month's export.
  • TRIM removes spaces at both ends and squeezes runs of spaces into one. It doesn't touch the non-breaking space from web pages.
  • Split text at a delimiter with TEXTBEFORE and TEXTAFTER, or LEFT, MID and FIND in older versions.
  • Numbers stored as text don't add up: VALUE or -- turns them into numbers.
  • A date written as 20260315 is a number to Excel. Rebuild it with DATE(LEFT, MID, RIGHT).
Jump straight to the practice sheet
On this page

Clean with formulas in a new column, one problem at a time: TRIM for stray spaces, TEXTBEFORE and TEXTAFTER to split and reorder text, VALUE for numbers stored as text, and DATE with LEFT, MID and RIGHT for dates written as plain digits. For a name written “Hart, Lena”, =TRIM(TEXTAFTER(A2,",")&" "&TEXTBEFORE(A2,",")) gives “Lena Hart”; in Excel 2021 or older, FIND with LEFT and MID does the same split. The formulas repeat on next month’s export, which retyping never will.

The question

“We get this customer export every month from an old system. Names come as ‘Surname, First name’ with random spaces, the amounts won’t add up, and the dates aren’t real dates. Clean it so we can use it, in a way that works next month too.”

The interviewer is less interested in any one function than in whether you can see what’s wrong with each column.

What they’re really testing

  • That you diagnose before you fix. Is it spaces? Text that looks like a number? A date that’s really a number?
  • That you keep the raw data. Clean in a new column, so the original is there to check against.
  • That your fix repeats. Formulas, not hand edits, because the export comes back every month.
  • That you know the traps. Spaces you can’t see, a number that’s secretly text, and a lookup that fails because of either.

Extra spaces

TRIM removes spaces at the start and end and squeezes every run of spaces between words into one:

B2=TRIM(A2)
RowAB
1Raw nameClean name
2 Lena Hart Lena Hart

Spaces matter more than they look: “Lena Hart “ with a trailing space doesn’t match “Lena Hart” in a lookup, so the lookup question fails with #N/A for no visible reason. =LEN(A2) exposes them: compare it with the number of letters you can see.

One trap to mention: text copied from a web page often has non-breaking spaces, which TRIM doesn’t remove. Replace them with ordinary spaces first, using SUBSTITUTE with CHAR(160).

Names in the wrong order

“Shah, Priya” needs to become “Priya Shah”. TEXTAFTER takes what follows the comma, TEXTBEFORE what precedes it. Join them with a space between and wrap the whole thing in TRIM, which removes the spaces that came along with the comma:

=TRIM(TEXTAFTER(A2,",")&" "&TEXTBEFORE(A2,",")) → Priya Shah

Without the outer TRIM, the result starts with the two spaces that followed the comma, and the cleaned name still won’t match anything:

Wrong=LEN(TEXTAFTER(A2,",")&" "&TEXTBEFORE(A2,","))12
Right=LEN(TRIM(TEXTAFTER(A2,",")&" "&TEXTBEFORE(A2,",")))10

The lengths tell the story: the untrimmed name is two characters longer than “Priya Shah”. In Excel 2021 or older, which have neither function, find the comma with FIND and cut with LEFT and MID instead (see the FAQ).

Numbers stored as text

Exports often bring numbers in as text: left-aligned, sometimes with a space, and ignored by SUM. Column B here is text, so its total is 0:

=SUM(B2:B4) → 0

=VALUE(TRIM(B2)) in a new column turns each one back into a number, and the new column adds up as it should:

C5=SUM(C2:C4)
RowABC
1InvoiceAmount (text)Amount
2INV-30112501250
3INV-302 980980
4INV-3032400 2400
5Total4630

A double minus in front, =--TRIM(B2), does the same. Data › Text to Columns › Finish fixes a whole column in place, if the interviewer asks for a non-formula way.

Dates that aren’t dates

A date written as 20260315 looks like a date to you and like a number (or text) to Excel. Formatting it as a date doesn’t help: read as a date, 20260315 is far past the last day Excel can show, so the cell just fills with # signs. Take it apart and build a real date:

B2=DATE(LEFT(A2,4),MID(A2,5,2),RIGHT(A2,2))
RowAB
1Raw dateDate
22026031515 Mar 2026

LEFT takes the year, MID the month, RIGHT the day, and DATE builds a date you can sort, filter and subtract. Once it’s a real date, TEXT can show it any way the report needs.

Common wrong answers, and why they fail

  1. Cleaning by hand. Fixed today, broken next month. Interviewers ask “and next month?” on purpose.
  2. TRIM on part of the result only. The spaces come back from whichever part you didn’t trim.
  3. Splitting at “, “ (comma and space). Works until a row has extra spaces after the comma, or none. Split at the comma and TRIM.
  4. Formatting text as a number. Changing a cell’s format doesn’t change what’s in it. The text stays text until VALUE (or Text to Columns) converts it.
  5. Overwriting the raw column. Keep it until the cleaned column is checked.

Practise it: a name for a mail merge

The other direction this time: the export has “First name Surname” with stray spaces, and the mail merge wants “Surname, First name”. Each name here is one first name and one surname. We check the result, then try a name that’s already clean and one with spaces at both ends.

Your task: In B2, turn the name in A2 into "Surname, First name" for a mail merge: no extra spaces, the surname first, then a comma and a space, then the first name.

Graded live
RowAB
1Raw nameMail merge name
2 Lena Hart

Write the formula in the bar above, then press Check or Enter.

Hint

TRIM(A2) cleans the name. In it, TEXTAFTER(…," ") is the surname and TEXTBEFORE(…," ") the first name: join them with ", ".

Solution

=TEXTAFTER(TRIM(A2)," ")&", "&TEXTBEFORE(TRIM(A2)," ") Any formula that returns the same result passes.

How to answer it in the interview

Walk the columns in order and name the problem before the fix: “Names have extra spaces and are surname-first, so TRIM and a split at the comma. Amounts are text, so VALUE. Dates are eight digits, so DATE with LEFT, MID and RIGHT. All in new columns, so it repeats next month.” That answer shows the habit they’re hiring for. More questions like this one: Excel interview questions.

Practise this in a lessonClean up messy namesA full exercise in the app's live grid, graded on what your formula calculates.Open the lesson

FAQ

Why doesn't TRIM remove all the spaces?

TRIM removes the ordinary space character. Text copied from a web page often has non-breaking spaces (CHAR(160)), which it leaves alone. Replace them first: =TRIM(SUBSTITUTE(A2,CHAR(160)," ")).

Should I clean data with formulas or with Find and Replace?

In an interview, formulas: they show your thinking and repeat on new data. Mention Text to Columns, Flash Fill and Power Query as tools for a one-off or a big recurring import.

How do I fix names in the wrong case?

PROPER capitalises the first letter of each word, UPPER and LOWER change every letter. Nest it around TRIM: =PROPER(TRIM(A2)).

What if I don't have TEXTBEFORE and TEXTAFTER?

Use FIND to locate the comma, then LEFT for the part before it and MID for the part after: =TRIM(MID(A2,FIND(",",A2)+1,LEN(A2))&" "&LEFT(A2,FIND(",",A2)-1)).

Summarize this guide withChatGPTPerplexityClaude

Keep going

Guides that build on this one.

All guides
Errors & fixesPractice sheet

#N/A error in Excel: what it means and how to fix it

#N/A means a lookup didn't find what it was looking for. Here are the six usual causes, how to spot each one on the sheet, and the fix, with a practice sheet.

2 min read · Updated
Interview prepPractice sheet

Working days and due dates: Excel interview question

Invoices due at the end of next month, and the working days a client has to pay: the date task interviewers set, solved with EOMONTH and NETWORKDAYS, plus a sheet that grades yours.

3 min read · Updated

Reading is step one. Writing the formula is the skill.

Practise in a live grid that grades what your formula calculates, with a specific hint when it's wrong.

Runs in your browser · Graded on your result · No install