Power Query vs DAX: Where Each Step Belongs
Not sure whether to clean data in Power Query or calculate in DAX? Use this simple rule, with examples for calculated columns, measures and the M language.
Short answer: A star schema splits your data into one central fact table (the events you count, such as sales) surrounded by dimension tables (the things you slice by, such as product, customer and date). Microsoft recommends it for Power BI because it gives simpler DAX, faster reports and smaller files.
Most Power BI reports start life as one giant table exported from somewhere. It works for a week. Then someone asks for a filter that spans two sources, a measure returns nonsense, and the file takes a minute to open.
I’ve experienced it first-hand when the granularity of table changed and that the business partners wanted to introduce a second-level of dimension aggregation.
The fix is almost always the same: reshape the data before you build anything fancy. Here is what that means in practice. The tables and columns are illustrative.
Draw it and you see the name. In the middle sits a fact table. Around it are dimension tables, each connected by a single line:
Product
|
Customer --- Sales --- Date
|
Store
Amount, Quantity) and keys pointing to the dimensions.Category, Country, Month).Microsoft’s guidance on star schema puts the roles simply: dimension tables handle filtering and grouping, and fact tables handle summarisation.
Three reasons show up in Microsoft’s documentation and in day-to-day work.
I make the same argument from the design side in Power BI design: model first, then calculation groups.
Say you have one table, SalesFlat, with columns like OrderID, OrderDate, CustomerName, Country, ProductName, Category, Amount. Here is the process I follow.
Step 1: Decide the grain of the fact table. What does one row represent? “One order line” is a good answer. If you can’t say it in one sentence, stop and find out.
Step 2: Pull out each dimension. In Power Query, duplicate SalesFlat and keep only the descriptive columns for one entity, for example ProductName and Category. Remove duplicates. Add an integer key if the source has none.
Step 3: Slim the fact table. Keep the keys (ProductKey, CustomerKey, DateKey) and the numeric columns. Remove the descriptive text columns you moved out.
Step 4: Add a proper date table. A dedicated Date table with one row per day, marked as the date table, is required for time intelligence. I show why in the time intelligence post.
Step 5: Create relationships. Each should be one-to-many, from the dimension (one side) to the fact (many side), with single-direction filtering. Hide the keys in the report view so nobody drags them into a visual.
No. For a quick one-off with a few thousand rows and one user, a single table is fine, and building a model for it is ceremony. The trouble starts when the report grows, more people use it, or a second source arrives. Then the cost of not having a model shows up all at once.
That is my opinion, and some teams get away with wide tables for a long time. If yours does, keep it.
Once the model is clean, calculations become the interesting part. A good next step is filter context and CALCULATE, because in a star schema they behave exactly as you would hope.
Sources: Microsoft Learn: Understand star schema and the importance for Power BI, Microsoft Learn: Many-to-many relationship guidance. Table and column names are illustrative.
Part of: Power BI & DAX