Sub topic 13
Power Query and source-side columns as alternatives
This chapter assumes you know Power BI Desktop's Report, Table and Model views, how a star-schema model relates tables, and basic DAX such as SUM and IF. It also assumes you know that a calculated column is computed row by row when the model refreshes. Here you will see two other places to create a column and when each is the better choice.
Three places to build a column
A column that you want to slice by does not have to be a DAX calculated column. You can create it in three places:
- A DAX calculated column is computed inside the model after the data loads.
- A Power Query column is computed in the Power Query Editor while the data is loaded, before it reaches the model.
- A source-side column is computed in the database, view, or file export that Power BI reads from.
All three end up as an ordinary column in the model, and a slicer or chart axis treats them the same way. The difference is where the work happens and who can reuse it.
The same column in each place
Take the Price Band column from earlier. In DAX it looks like this:
Price Band = IF(Product[List Price] >= 100, "High", "Standard")In Power Query, you add a custom column with the M language:
if [List Price] >= 100 then "High" else "Standard"In the source, the same rule could be part of a SQL view:
SELECT ProductID,
ListPrice,
CASE WHEN ListPrice >= 100 THEN 'High' ELSE 'Standard' END AS PriceBand
FROM dbo.Product;Why prefer Power Query or the source
Moving the logic upstream has practical benefits:
- Better compression. Power Query and source columns are loaded together with the rest of the table. A DAX calculated column is built after load, and it can compress less well than a column loaded with the table.
- Query folding. If Power Query can translate a step into SQL, the database does the work. This is called query folding. It keeps refresh fast and keeps the heavy calculation off the model.
- Reuse. A column in the source is available to every report and tool that reads it. A DAX column exists only in one model.
- Simpler model. Keeping row-level shaping in the data preparation layer leaves the model for relationships and measures.
Why still use a DAX calculated column
DAX columns win in some cases:
- The logic needs other tables through relationships, such as
RELATED, and the relationship exists only in the model. - The logic depends on model-only objects, such as a column from another calculated table.
- You cannot change the source, and the data preparation layer is not available to you.
A simple rule of thumb
Push the column as far upstream as you can. Prefer the source, then Power Query, then DAX. Stop at the first place that can express the logic and that you are allowed to change.
| Place | Best for | Main limit |
|---|---|---|
| Source-side column | Logic shared by many reports | Needs access to change the source |
| Power Query column | Cleaning and row-level shaping | Cannot use model relationships |
| DAX calculated column | Logic that uses related tables | Larger model, slower refresh |
Exercise
A Sales table needs a "Year-Month" text column for a chart axis. The data comes from a SQL database you cannot edit. Where should you create the column, and why?
Show answer
Create it in Power Query. The logic uses only the row's own date, so it does not need model relationships. Power Query may fold the step into SQL, and the column loads with the table. A DAX calculated column would also work but is later in the pipeline and can compress less well. A measure cannot be used because the column is needed on an axis.