Skip to content

Clean columns as steps in Power Query

Power Query basics9 minPremium

Builds on Load data into Power Query and set column types and Tidy text with TRIM, CLEAN, UPPER and PROPER.

A membership coordinator at a sports club in Hamburg exports the member list every quarter. The names come in capitals with spaces around them, last and first name in one column, with n/a where a phone number is missing and the system's test accounts mixed in.

How it works

Each command in the editor adds a step to Applied Steps, and the preview shows the table after it.

  • Transform > Format holds Trim, which removes the spaces at the start and the end of the text and, unlike Excel's TRIM, leaves a double space between words as it is. Clean removes characters that don't print, and lowercase, UPPERCASE and Capitalize Each Word change the capitals.
  • Home > Split Column > By Delimiter splits a column at a character or a string, such as a comma followed by a space, at each one or only at the left-most or right-most. The new columns take the old name with .1 and .2. Double-click a heading to rename it.
  • Home > Replace Values swaps one value for another. Under Advanced options, Match entire cell contents changes only the cells that hold exactly that value.
  • The arrow on a heading filters the rows, by ticked values or with Text Filters such as Does Not Begin With, and Home > Remove Rows removes blank rows and duplicates. Text filters match capitals exactly.

Click a step in Applied Steps to see the table at that point, and the X beside a step deletes it. Steps run from the top, so a later step that names a column an earlier step removed or renamed stops with an error.

Example

The coordinator's names, step by step:

Each step works on the table the step before it left. Trimming first matters, since a space in front of a name would split it before the first name.

Common mistakes

  • Splitting before trimming. A space in front of a name splits it before the first name, and the first piece comes out empty. Trim first.
  • Replace Values without Match entire cell contents. It changes the text inside longer values too. Tick it when the whole cell should match.
  • Ticking names in a filter to drop test accounts. Next quarter's new test account gets through. Use a Text Filter such as Does Not Begin With.

In short

  • Trim, Clean and the capitals are under Transform > Format, and Trim only touches the ends.
  • Split Column by Delimiter takes a character or a string, then rename the new columns.
  • Filter with rules, which keep working on next quarter's data.

Practice

Premium

4 exercises: 3 queries and 1 quiz question.

Practice is part of Premium

Every lesson is free to read, and you can practice the free lessons without an account. This lesson's exercises are part of Premium, which you add to a free account.