Skip to content

ETL Best Practices

These are habits worth following when designing queries and the models they feed. None is a strict rule, but each one saves work or speed later.

Shape the data as near its source as you can

Section titled “Shape the data as near its source as you can”

The earlier in the chain a transformation happens, the more reports can share it.

A report can get its data into shape at several points: in the source database, in a query, or in the model itself.

One option is to write a SQL statement and paste it into the query that extracts the data. That works, but it ties the logic to one dataset, so the next report that needs similar data has to copy the statement or write it again.

Power Query’s own tools can do almost any reshaping without help from anyone else, which is their strength. Even so, they are the place for work that only one report needs. If several reports need data in the same shape, and the people who run the source system (often IT) can provide it in that shape, it is usually better to ask them to, so the work is done once for everyone.

Shape in Power Query, model in Power Pivot

Section titled “Shape in Power Query, model in Power Pivot”

Power Query and Power Pivot do different jobs. Power Query cleans and reshapes data on its way in, and Power Pivot, the engine behind the Data Model, holds the data and calculates the measures that reports use.

Power Pivot can reshape data too, through calculated columns and calculated tables, but the work belongs in Power Query. Shape the data there, before or as it loads, and keep Power Pivot for measures and reporting.

Any calculation over time needs a calendar table.

A calendar table with one row per day, with columns for DateKey, Year, Quarter, Month, MonthName, YearMonthNumber and YearQuarterNumber

Plenty of analysis works on a single flat table with no lookup tables at all. Time calculations are the exception, such as year to date or the same period last year. DAX’s time intelligence functions expect a calendar table, which is a lookup table with one row for every date and columns that group the dates into months, quarters and years.

Power Pivot works best when the tables form a star schema.

A star schema with a factAbsence table in the centre, related one-to-many to dimAbsenceCode, dimFacility, dimStaff, dimStudent and dimDate around it

In a star schema, one fact table of events sits in the middle, and each lookup table, also called a dimension table, is related to it directly. Other layouts can work, and are not always slow, but designing towards a star schema is a sound default, both for the model and for deciding what each query should produce.

A fact table, which records events such as sales or purchases, works better long and narrow than short and wide.

The same quantities laid out two ways: a short, wide table with a column for each month, marked bad, and a long, narrow table with Product, Month and Quantity columns, marked good

There are two reasons:

  • Power Pivot stores data by column and compresses each column. A long, narrow table compresses better than a short, wide one, so it takes less space and is quicker to read.
  • Power Pivot is built to filter. One measure that adds up a single Quantity column can be sliced by a Month column. In the wide layout, each month needs a measure of its own.

Unpivot Columns, on the Transform tab, turns the wide layout into the narrow one.

Load every column the reports use, and no others.

Each column that is loaded but not used makes the workbook larger and slower. Remove such columns in the query.

Before Power Query, it made sense to ask IT for every column, because getting another one added later was slow. That reason has gone: if a column is needed later, add it to the query then. The tables that matter most are the large fact tables, since lookup tables are usually small enough that a spare column costs little.

  • Slowly changing datasets: how to build queries that cope with data whose structure changes over time. Read more

The advice on this page follows Matt Allington’s post Best Practices for Power Pivot, Power Query and Power BI on Excelerator BI.