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
- Select the table and go to Data, From Table/Range to open it in the Power Query Editor.
- Select the text column, then go to Transform, Format, Trim, to remove leading and trailing spaces.
- With the same column selected, go to Transform, Format, Clean, to remove non-printable characters.
- Check the distinct values in the column before and after, and confirm variants have merged.
- 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.
