Power Query: A Friendly Guide to Cleaner Data
If you spend any amount of time tidying spreadsheets by hand, Power Query is worth an afternoon of your attention. It is a data preparation tool built into Excel and into Power BI, and its job is simple to describe: it takes messy data from somewhere, reshapes it into something usable, and remembers every step so you never have to repeat the work.
What it actually does
Power Query follows the classic pattern of extract, transform and load. You connect to a source, apply a series of transformations, then send the finished table into a worksheet or into a data model. The important difference from ordinary spreadsheet editing is that nothing is done permanently to the original data. Instead, Power Query records your steps as a recipe, and each time the source changes you refresh, and the whole recipe runs again. What took an hour of copying and pasting becomes a single click.
Where it comes from
Read more
Power Query began life as a separate add-in for Excel and was later folded straight into the ribbon, on the Data tab, as well as into Power BI. The underlying engine is shared across Microsoft's data products, which is why the same skills transfer between them. The scripting language behind it, known as M, is what you see if you open the advanced editor, though most people work entirely through the point-and-click interface.
The main pieces to learn
- Connections. Where the data lives: a workbook, a folder of files, a database, a web table. Many sources need credentials, so set those up once and reuse them.
- Applied Steps. The list of transformations that makes up your query. Each step can be renamed, reordered within limits, or deleted.
- Merging and appending. Merging joins tables side by side on a matching column; appending stacks tables on top of one another. Together they cover most combining tasks.
- Unpivoting. Turning wide tables, where months or categories spread across many columns, into tall ones that are far easier to analyse.
- Data types. Every column needs the right type. Text that looks like a number is not a number, and mismatches are the most frequent cause of strange results.
Practical habits worth building
Name your steps as you go, so the list reads like a description of what you did rather than a wall of "Changed Type1". Clean data in Power Query rather than after loading it, otherwise the cleaning is lost on refresh. Keep source files in a stable location, since a moved file breaks the connection. Separate a large job into smaller queries that feed into one another, which makes each part easier to test. And check your query on a small sample before running it against a large dataset.
A closing thought
Power Query rewards patience more than cleverness. Start with one awkward file you deal with regularly, build a query for it, and notice how much of your week it quietly gives back.