Power Query Lesson 2: Cleaning Text — Trim, Case and Split

📎 This article includes 2 downloadable practice files ↓

⏱ 3 min read

📘 Power Query Beginner Course · Lesson 2 of 10

In this article
  1. Format: trim, clean, case
  2. Replace values
  3. Split column
  4. Check your work
  5. Where beginners go wrong
  6. Practice

“ SHARMA TRADERS ”, “sharma traders” and “Sharma Traders” are the same customer to you and three different ones to a pivot table. Power Query’s text tools fix a whole column in a click, and repeat the fix on every refresh.

Format: trim, clean, case

Select the Customer column › Transform › Format:

  • Trim: removes spaces at the start and end. (Unlike Excel’s TRIM, it doesn’t squeeze double spaces inside; use Replace Values “ ” → “ ” for that.)
  • Clean: removes non-printing characters from exports.
  • Capitalize Each Word, UPPERCASE, lowercase.

Select several columns first to apply the same step to all of them.

Replace values

Right-click a column › Replace Values: “Pvt. Ltd.” → “Pvt Ltd”, “N/A” → empty. Advanced options matches the entire cell only, so “North” doesn’t change inside “Northeast”.

Split column

The Location column holds “North – Delhi”. Right-click › Split Column › By Delimiter › Custom: - (space dash space) › Each occurrence. Rename the new columns Region and City (double-click the header).

Other options: by number of characters, by positions, by uppercase-to-lowercase changes, and into rows (one row per item for lists like “Pens, Files, Staplers”).

💡 Prefer Add Column > Extract (Text Before Delimiter, Text After Delimiter, First Characters) when you want to keep the original column for checking.

Check your work

Click the drop-down on the Customer column: the filter list shows distinct values. After cleaning, each customer appears once. View › Column distribution shows distinct and unique counts under each header.

⚠️ Column profiling looks at the first 1,000 rows by default. Click the status bar text ‘Column profiling based on top 1000 rows’ to switch to the entire data set before trusting the counts.

Where beginners go wrong

Mistake Fix
Expecting Trim to remove double inner spaces Replace ” ” with ” ” (repeat if needed)
Splitting at “-” when names contain hyphens Split at the left-most delimiter only, or use ” – ” with spaces
Capitalize Each Word on codes like “GSTIN” Apply case changes to name columns only

Practice

Download the source file(s) and the expected-results workbook below. Build the query in Excel (Data › Get Data), load it to a sheet, and compare your row count and totals with the Checks sheet.

📎 Practice files for this article

  • 🧾
    pq-02-messy-text.csvCustomer names in mixed case with spaces, and a combined "Region - City" column.
    ⬇ CSV · 4 KB
  • 📗
    Expected resultsWhat your query should produce, with check totals.
    ⬇ XLSX · 8 KB

Free to use for learning. Files with macros (.bas) are plain text — import them with Alt+F11 → File → Import File, and always test on a copy.

✨ Ask AI about this article

Stuck on a step? Ask a question and the AI answers using this article.

Free · AI can be wrong

Leave a Reply

Your email address will not be published. Required fields are marked *