Advanced Excel for Data AnalystsLesson 17 of 49
Lesson 17 of 49

String Cleansing, Normalization & Merging: TRIM, CLEAN, TEXTJOIN

Overview & Learning Objectives

Messy data exports from ERP systems arrive full of rogue line breaks, trailing spaces, and inconsistent casing. Normalizing strings with TRIM, CLEAN, PROPER, and merging them with TEXTJOIN builds clean customer databases.

  • Remove invisible ASCII characters and irregular spacing with TRIM and CLEAN.
  • Standardize names into proper title casing with PROPER.
  • Concatenate multi-column address fields with TEXTJOIN, safely skipping empty cells.

Industry Standard

Standard: E-commerce dispatch hubs at Flipkart and Amazon standardize shipping label addresses into single-line formats using TEXTJOIN with comma delimiters.

Real-World Example: E-Commerce Address Concatenation & Data Normalization

At QuickShip Logistics, delivery addresses arrive across 4 separate columns: Flat No, Street, City, and Pincode. Some rows lack Flat No. TEXTJOIN merges them with clean commas while automatically skipping empty cells.

Flat / HouseStreetCityPincodeCombined Clean Address
Flat 402Green Glen LayoutBangalore560103Flat 402, Green Glen Layout, Bangalore, 560103
MG RoadBangalore560001MG Road, Bangalore, 560001 (skips blank)
Plot 12Banjara HillsHyderabad500034Plot 12, Banjara Hills, Hyderabad, 500034

Functions Covered in this Chapter

Here is the definition, exact syntax, parameter breakdown, and real-world business example for each function covered in this chapter:

Function 1

TRIM Function

Definition: Removes all leading spaces, trailing spaces, and redundant double spaces from text, leaving only single spaces between words.

Syntax:
=TRIM(text)
Parameters Breakdown:
  • text: The cell containing text with irregular spacing.
Real-World Example (Clean Trailing Spaces):
Problem / Scenario: Clean `" Rohit Sharma "` so VLOOKUP exact match can find it.
Formula: =TRIM(" Rohit Sharma ")
Result: "Rohit Sharma"
Why it works: Removes the 2 leading spaces, 2 trailing spaces, and reduces 3 middle spaces to 1.
Function 2

CLEAN Function

Definition: Removes all non-printable ASCII characters (ASCII codes 0 through 31, including line breaks and tabs) imported from database exports.

Syntax:
=CLEAN(text)
Parameters Breakdown:
  • text: The text containing line breaks or unprintable characters.
Real-World Example (Remove Line Breaks):
Problem / Scenario: Strip line feeds from a multi-line address cell into a single row.
Formula: =CLEAN(A2)
Result: Single-line clean string
Why it works: Removes Alt + Enter line feeds instantly.
Function 3

TEXTJOIN Function

Definition: Combines the text from multiple ranges and/or strings, using a specified delimiter between each text item, with an option to ignore empty cells.

Syntax:
=TEXTJOIN(delimiter, ignore_empty, text1, [text2], ...)
Parameters Breakdown:
  • delimiter: The separator string placed between items (e.g. ", " or " - ").
  • ignore_empty: TRUE ignores blank cells; FALSE includes empty delimiters.
  • text1, [text2]: The strings or cell ranges to join (e.g. A2:D2).
Real-World Example (E-Commerce Shipping Address Merger):
Problem / Scenario: Join address columns A2:D2 separated by commas, skipping empty fields.
Formula: =TEXTJOIN(", ", TRUE, A2:D2)
Result: "MG Road, Bangalore, 560001"
Why it works: Delimits with comma and space, cleanly ignoring the empty Flat No cell.
Function 4

PROPER Function

Definition: Capitalizes the first letter of every word in a text string and converts all other letters to lowercase.

Syntax:
=PROPER(text)
Parameters Breakdown:
  • text: The text string to convert to title case.
Real-World Example (Customer Name Standardization):
Problem / Scenario: Standardize `"sAcHiN gArG"` into professional title case.
Formula: =PROPER("sAcHiN gArG")
Result: "Sachin Garg"
Why it works: Capitalizes S and G, lowercases all other letters.

Common Mistakes & Limitations

  • Assuming TRIM removes the non-breaking space character (`CHAR(160)`) common in web scraped data. Use `=TRIM(CLEAN(SUBSTITUTE(A2, CHAR(160), " ")))` for bulletproof cleaning.
  • Using old `CONCATENATE()` which does not support ranges and cannot automatically ignore blank cells.

Keyboard Shortcuts

ActionWindowsMac
Uppercase / Lowercase (Word toggle)Shift + F3 inside WordShift + F3
Flash Fill Pattern RecognitionCtrl + ECtrl + E

Pro Tips & Modern Alternatives

  • Power Query -> Transform -> Format -> Capitalize Each Word & Trim provides 1-click batch cleanup for 100,000+ rows.
  • Use `&` operator (`=A2 & " " & B2`) for simple two-cell joins.