Skip to content

Overview

Data rarely arrives ready to analyse. Before a report can be built on it, someone usually has to deal with problems such as these:

  • rows that appear more than once
  • names spelt two different ways
  • blank cells
  • dates that are not valid dates
  • numbers stored as text
  • cells that hold errors
  • percentages written as whole numbers
  • long formulas that are hard to check
  • mistakes that creep in when the same manual steps are repeated every month

ETL, short for extract, transform and load, is the name for the work of fixing these problems in a repeatable way: extracting the data from where it lives, transforming it into a usable shape, and loading it to where it will be analysed. Doing it with a tool rather than by hand means the time goes on the analysis instead of on the preparation.

This guide uses Power Query, Microsoft’s ETL tool for Excel and Power BI. It starts with the basics and works up to the techniques that solve real business data problems.

Power Query loads data into Excel or Power BI from other sources, and reshapes it on the way in. It began as a free add-in for Excel and is now built in, on Excel’s Data tab under Get & Transform Data, and in Power BI as Transform data.

It belongs to a group of tools known as self-service business intelligence. The name reflects who does the work: the analysts, accountants, managers and engineers who use the data also build the reports, without waiting for an IT department to prepare the data for them. Power Query was one of the first ETL tools designed for these business users rather than for database developers.

The three letters of ETL describe its three jobs:

  1. Extract. Power Query connects to a source, such as a workbook, a folder of CSV files, a database or a web page, and brings the data into one place. The connection is kept, so when the source changes, refreshing the query fetches the new data.
  2. Transform. Power Query cleans and reshapes the data into the layout the report needs. The steps are written once and replayed on every refresh, even when the source data has changed.
  3. Load. Power Query delivers the result to a worksheet table, to the Excel Data Model, or to a Power BI report.

Power Query is worth learning if any of these sound familiar:

  • Reshaping. The data arrives in a layout that cannot be used as it is, and nobody upstream can change it, so it is rearranged by hand every time.
  • Cleaning. The same known errors have to be removed from every month’s data, because they cannot be fixed at the source.
  • Collating. Hours go on copying data from several files or sheets into one workbook before any work can start.
  • Joining. Tables are joined with XLOOKUP or VLOOKUP formulas, filled down a column that never quite matches the length of the data.
  • Scraping. Data is copied from web pages and then tidied by hand.
  • Comparing. Two lists are compared to find what is in one and not the other, using lookups and INDEX and MATCH.
  • An interface that is quick to learn. Most transformations are a button or a menu item, and Power Query writes the code behind them.
  • A full language underneath. Every step is written in M, Power Query’s formula language, which can do far more than the buttons offer. M looks nothing like Excel formulas or VBA, so it takes some learning, and later pages in this guide show where it is worth it.
  • Repeatable steps. Power Query records each transformation as a step in a list. The source data is never changed, and clicking any step shows the data as it was at that point. The same steps can then be run against next month’s file, as long as it has the same layout.
  • Query folding. Where the source is a database, Power Query translates its steps into a query that the database runs, such as a single SQL SELECT statement. Filtering and joining a large table then happens on the database server, and only the result is downloaded, which is much faster than fetching the whole table first.

Excel and Power BI also contain the Data Model, sometimes called Power Pivot: a database engine that holds data in memory, compressed, and can store far more rows than a worksheet’s limit of 1,048,576. Data in the Data Model can feed a PivotTable directly, without a worksheet to hold it, and CUBE functions can pull single values from it into cells for custom layouts.

The Data Model adds things a worksheet cannot do:

  • Several related tables. Tables are linked by relationships, so a PivotTable can draw on all of them at once, where a normal PivotTable reads a single table.
  • Calculations in DAX. DAX, the Data Model’s formula language, handles calculations that are awkward in worksheet formulas, such as year-on-year comparisons and shares of a total.
  • Smaller files. The compression usually makes a workbook much smaller than the same data on worksheets.
  • Hierarchies. A predefined drill-down path, such as year, then quarter, then month, can be added to a table.

The Data Model is not Power Query, though. The two do different jobs in sequence: Power Query cleans and shapes the data, and then loads it into the Data Model, where it is modelled and analysed.

The rest of this guide shows Power Query and M at work on practical business problems, one technique per page.