New Tool Radar

AI for Data & Spreadsheets

How to Trim and Clean Text with Power Query in Excel

Trim spaces and remove non-printable characters from a text column with Power Query so lookups match.

Schematic illustration for How to Trim and Clean Text with Power Query in Excel: three numbered steps - From Table/Range; Transform, Trim and Clean; Check lookups match.

Text copied from a web page often carries leading spaces and invisible characters that make two identical-looking values different to Excel. Power Query Trim removes the extra spaces and Clean removes the non-printable characters, so lookups and filters match the values they should.

Prerequisites

  • Excel with Power Query
  • A table with messy text values
  • A copy of the source file, so the original stays untouched.

Steps

  1. Select the table and go to Data, From Table/Range to open it in the Power Query Editor.
  2. Select the text column, then go to Transform, Format, Trim, to remove leading and trailing spaces.
  3. With the same column selected, go to Transform, Format, Clean, to remove non-printable characters.
  4. Check the distinct values in the column before and after, and confirm variants have merged.
  5. Click Close and Load, then test a lookup on a value that failed before.

Worked example: Fictional supplier names after trimming

The practice table below is a fictional five-supplier list after trimming. The count column is 1 per supplier, and the total is the number of suppliers. The table below is fictional practice material, with fictional values. It is the expected result, worked out by hand, not a run of any tool.

Supplier Count
Northgate Supplies 1
Greenfield Foods 1
Harbour Books 1
Meadow Crafts 1
Riverside Toys 1
Total 5

Expected result. Five suppliers, each counted once, and a lookup on any supplier name now finds its row.

Limits

  • Trim does not remove non-breaking spaces from web exports, so Clean may be needed as well.
  • Trimming changes the stored value, so keep a copy of the original column until the check is done.

Sources

See all