Sub topic 13
Flash Fill and Power Query as Alternatives
This chapter assumes you can enter and copy formulas, use relative references such as A2, and tell text from numbers in a cell. You have already cleaned text with TRIM, CLEAN, PROPER, and SUBSTITUTE. Formulas are not the only way to do this. This chapter covers two other tools and how to choose among the three.
Why consider an alternative
A formula such as =PROPER(TRIM(CLEAN(SUBSTITUTE(A2,CHAR(160)," ")))) works, but it needs a helper column. You then have to paste values to keep the result. Flash Fill and Power Query handle the same jobs with different trade-offs.
Flash Fill: cleaning by example
Flash Fill is a feature that watches you type a result next to your data. It guesses the pattern and fills the rest of the column. It writes static values, not formulas, so there is no helper column to paste over.
To use it:
- Put the raw text in column A, starting at A2.
- In B2, type the cleaned version of A2 by hand. For example, type
Maria Gomezif A2 holdsmaria GOMEZ. - Start typing the cleaned version of A3 in B3. Excel shows a gray preview for the rest of the column.
- Press Enter to accept it. You can also press Ctrl+E, or choose Data, then Flash Fill.
Flash Fill works best when the pattern is visible in a few examples. It struggles when the rows are inconsistent, and it never explains what rule it used. A formula states its rule, so you can inspect and audit it.
Power Query: a repeatable cleaning step
Power Query is Excel's data-transformation tool. You load a table into the Power Query Editor, apply steps, and load the result back to a worksheet. Excel records each step. When the source data changes, you refresh the query and every step runs again.
The steps for basic cleanup are:
- Select a cell in your data and choose Data, then From Table/Range. Confirm that the range is a table.
- In the editor, select the text column.
- On the Transform tab, choose Format, then Trim, then Clean, then Capitalize Each Word.
- Choose Home, then Close & Load.
These commands map to the functions you know, with two differences worth knowing:
| Excel function | Power Query command | Difference |
|---|---|---|
| TRIM | Format, then Trim | Power Query Trim removes leading and trailing spaces only. It does not collapse runs of spaces between words. |
| CLEAN | Format, then Clean | Removes control characters. |
| PROPER | Format, then Capitalize Each Word | Follows its own capitalization rules, so check names and abbreviations. |
The first row matters. A worksheet TRIM also reduces runs of inner spaces to one space. If your data has doubled spaces inside values, Power Query needs an extra step, such as a Replace Values step.
Power Query also treats non-breaking spaces differently from TRIM, so test your data instead of assuming. You can use Replace Values to swap character 160 for a normal space before trimming.
Choosing among the three
| Situation | Best choice |
|---|---|
| One-time cleanup of a short list with an obvious pattern | Flash Fill |
| Results must change when the source cell changes | Formulas |
| You need to see and audit the exact rule | Formulas |
| The same cleanup repeats on each new export | Power Query |
| Large data sets with many cleaning steps | Power Query |
Formulas remain the most transparent option, and they work in every version of Excel. Power Query suits recurring imports. Flash Fill is the quickest for small one-off jobs, and it is the least predictable.
Exercise
Each week you receive a new export with the same messy name column, and you want the cleanup to happen without rebuilding anything. Which tool fits best, and why would Flash Fill be a poor choice?
Show answer
Power Query fits best. It records the cleaning steps and re-runs them when you refresh with the new data. Flash Fill writes static values and does not update, so you would have to redo it for every export.
Exercise
A column has the value "John Smith" with three spaces between the words. You use Power Query's Trim command and the spaces remain. Why, and how do you fix it?
Show answer
Power Query's Trim removes only leading and trailing spaces, so spaces between words stay. Add a Replace Values step that replaces two spaces with one, and repeat it as needed, or use another transformation that collapses the runs.