Course: Data Transformation in Power BI
Reshaping data with DAX in Power BI is a fundamental skill that lets analysts convert raw tables into analysis-ready datasets. Calculated tables, created with functions like CALENDAR, enable consistent time intelligence by generating date ranges tied to your fact tables. SUMMARIZECOLUMNS and SUMMARIZE provide flexible grouping and aggregation, allowing you to compute measures such as total orders or average profit per order. DAX queries (EVALUATE ... ORDER BY) let you retrieve model data directly and control sorting and pagination with clauses like ORDER BY and START AT. Power Query complements DAX by handling structural transformations—pivot, unpivot, transpose, merge, and append—before data enters the model. Handling nulls is essential: use COALESCE, ISBLANK, or explicit filters to avoid misleading aggregates and to maintain data integrity. Joins in Power Query (left/right/inner) or DAX joins (NATURALLEFTOUTERJOIN) determine which rows are preserved when combining tables. Variables (VAR) and RETURN in DAX help make complex calculations more readable and performant by storing intermediate results. Ranking (RANKX) and statistical measures (STDEVX.P, Z-score calculations) are practical ways to surface outliers and relative performance. Always explicitly define ordering in DAX queries because model or report sort metadata is not automatically applied in query results. When designing solutions, prefer Power Query for row/column shape changes and use DAX for semantic aggregations, measures, and calculated tables that rely on the model’s relationships. Clear naming and comments (rename steps and use // or /* */) improve maintainability and teamwork. Together, DAX and Power Query form a complementary toolkit for reshaping, aggregating, and analyzing data at scale in Power BI.Lesson
Topic: Reshaping Data — DAX & Power Query techniques for transformation, aggregation, and querying in Power BI
Learning Outcomes
- Understand how to create calculated tables (e.g., calendar tables) using DAX.
- Use SUMMARIZECOLUMNS and related functions to group and aggregate data.
- Execute DAX queries to retrieve, sort, and paginate results from the model.
- Apply Power Query operations: pivot, unpivot, transpose, merge, and append.
- Handle nulls, use variables, and implement rankings and statistical measures.
Conceptual Explanation
Reshaping data is the process of converting data between wide and long forms, aggregating, and creating semantic structures that support analysis. In Power BI, transformations can be applied either in Power Query (M language) during data ingestion or in the model layer using DAX. Use Power Query to perform structural changes—pivot/unpivot, transpose, merge (joins), and append (union of similarly-structured tables). Use DAX for model-level constructs: calculated tables (CALENDAR), calculated columns, measures, grouping and aggregation (SUMMARIZE / SUMMARIZECOLUMNS), ranking (RANKX), and statistical calculations (STDEVX.P).
Key DAX examples:
-- Calendar table
Dim_Calendar = CALENDAR(MIN('Fact_StrategyPlan'[Datekey]), MAX('Fact_StrategyPlan'[Datekey]))
-- Summarize by month and category
EVALUATE
SUMMARIZECOLUMNS(
'Date'[Month Name],
'Date'[Month of Year],
'Product'[Category],
FILTER( VALUES('Product'[Category]), [Category] = "Clothing" ),
"Orders", [Orders],
"Avg Profit per Order", DIVIDE([Total Sales Profit], [Orders])
)
-- Query with ordering and start point
EVALUATE
'Sales Order'
ORDER BY 'Sales Order'[Sales Order] ASC
START AT "SO43661"
Bilingual (EN → বাংলা)
English: Create calculated tables with CALENDAR for time intelligence; use SUMMARIZECOLUMNS to group and compute measures; perform shape changes in Power Query; control DAX query ordering explicitly.
বাংলা: সময়-নির্ভর বিশ্লেষণের জন্য CALENDAR দিয়ে ক্যালেন্ডার টেবিল তৈরি করুন; SUMMARIZECOLUMNS ব্যবহার করে গ্রুপিং ও মেজার গণনা করুন; ডেটার আকার পরিবর্তনের কাজ Power Query-তে করুন; DAX কুয়েরিতে অর্ডারিং স্পষ্টভাবে নির্ধারণ করুন।
Important Notes
- Power Query (M) is best for structural/shape transformations before data loads to the model.
- DAX is best for semantic calculations, measures, and calculated tables that use model relationships.
- DAX queries do not inherit the report sort order—use ORDER BY inside the query.
- Use COALESCE or ISBLANK to manage nulls; filters can exclude null categories from aggregates.
- Rename steps and add comments (// or /* */) to improve readability and collaboration.
Exercises
True / False
- Calculated tables created with DAX are refreshed automatically when the model refreshes.
- Power Query transformations are applied after DAX calculations in the data pipeline.
- SUMMARIZECOLUMNS can group by multiple columns and compute measures per group.
Answer
True. Calculated tables defined in DAX are recalculated during model refresh and will reflect updated source data or related measures.
Answer
False. Power Query transformations (M) are applied before data loads into the model; DAX calculations operate on the model after loading.
Answer
True. SUMMARIZECOLUMNS accepts multiple group-by columns, optional filters, and returns computed expressions per row.
Fill in the Blanks
- To create a continuous date table in DAX you can use the ________ function.
- To avoid division-by-zero when computing ratios in DAX, use the ________ function.
- In Power Query, the operation that converts multiple period columns into rows is called ________.
Answer
CALENDAR
Answer
DIVIDE
Answer
Unpivot (often "Unpivot Columns")
Multiple Choice Questions (MCQ)
- Which function ranks items by a measure in DAX?
- RANKX
- RANK
- POSITION
- ORDERBY
Answer
a) RANKX
- Which clause controls starting row in a DAX query?
- OFFSET
- START AT
- BEGIN FROM
- FIRST ROW
Answer
b) START AT
Matching
| Operation | Best Place |
|---|---|
| Pivot / Unpivot | Power Query |
| Calculated Measure | DAX (Model) |
| Create Calendar Table | DAX or Power Query (prefer DAX for model-aware tables) |
Answer
- Pivot / Unpivot → Power Query
- Calculated Measure → DAX (Model)
- Create Calendar Table → DAX (CALENDAR) (Power Query alternative possible)
Descriptive
- Explain when you would use Power Query versus DAX for reshaping data.
- Describe a step-by-step approach to create a summarized table of monthly orders for one product category.
- Ensure a Date dimension exists (create with CALENDAR if needed).
- Confirm relationships: fact table → Date, Product dimension linked appropriately.
- Define measures: [Orders], [Total Sales Profit].
- Use SUMMARIZECOLUMNS grouping by 'Date'[Month Name], 'Date'[Month of Year], 'Product'[Category].
- Apply FILTER( VALUES('Product'[Category]), 'Product'[Category] = "Clothing" ) to restrict the category.
- Compute additional expressions like DIVIDE([Total Sales Profit],[Orders]) for averages and include ORDER BY 'Date'[Month of Year] ASC for chronological output.
Answer
Use Power Query (M) when you need to change row/column structure, merge or append sources, or clean and normalize data before it enters the model. Use DAX when you need model-aware calculations, measures, ranking, or calculated tables that rely on relationships and measures created in the model.
Answer
Creative
- Design a small analysis plan (3 steps) to find top 5 products by Z-score of monthly sales.
- Create a monthly sales summary table (group by Product, Month) using SUMMARIZE or in Power Query aggregate to monthly granularity.
- Compute mean and standard deviation per product across months and calculate Z-score: Z = (Sales - Mean) / StdDev (use STDEVX.P or STDEV.P and variables in DAX).
- Rank by Z-score (RANKX) and filter/topN to extract top 5 product-month combinations; visualize with a bar or table and annotate outliers.
Answer
Activities
- Hands-on: Create Dim_Calendar using CALENDAR for your dataset and relate it to the fact table.
- Exercise: Use Power Query to unpivot quarterly sales and then build a SUMMARIZECOLUMNS query to aggregate monthly sales.
- Lab: Implement COALESCE to replace null customer names with "Unknown" and show the difference in aggregate counts.
Vocabulary
- CALENDAR — DAX function to generate date ranges.
- SUMMARIZECOLUMNS — DAX function to group and return tabular summaries with expressions.
- UNPIVOT / PIVOT — Power Query operations to change data orientation.
- START AT — DAX query clause to control result pagination.
- COALESCE / ISBLANK — Functions to handle nulls and blanks.
- RANKX, STDEVX.P — DAX functions for ranking and standard deviation calculations.
Homework
- Create a calculated table Dim_Calendar for your dataset and add Month, Quarter, Year columns.
- Build a DAX query that summarizes Orders and Avg Profit per Order for the "Clothing" category and sorts by Month.
Answer
Use: Dim_Calendar = CALENDAR(MIN('Fact_StrategyPlan'[Datekey]), MAX('Fact_StrategyPlan'[Datekey])) and then ADDCOLUMNS to generate MonthName, MonthOfYear, Quarter, Year.
Answer
EVALUATE
SUMMARIZECOLUMNS(
'Date'[Month Name],
'Date'[Month of Year],
FILTER( VALUES('Product'[Category]), 'Product'[Category] = "Clothing" ),
"Orders", [Orders],
"Avg Profit per Order", DIVIDE([Total Sales Profit], [Orders])
)
ORDER BY 'Date'[Month of Year] ASC
Practice Task
Given separate tables Sales_2021 and Sales_2022 with identical columns, create a unified table and a summary that shows total sales per product category.
Answer
Use UNION with SELECTCOLUMNS to harmonize names, then SUMMARIZECOLUMNS on the unified table. Example:
Unified_Sales =
UNION(
SELECTCOLUMNS(Sales_2021, "OrderID", Sales_2021[OrderID], "ProductID", Sales_2021[ProductID], "Total Sales", Sales_2021[TotalSales]),
SELECTCOLUMNS(Sales_2022, "OrderID", Sales_2022[OrderID], "ProductID", Sales_2022[ProductID], "Total Sales", Sales_2022[TotalSales])
)
EVALUATE
SUMMARIZECOLUMNS(
'Product'[Category],
"Total Sales", SUM(Unified_Sales[Total Sales])
)
End of lecture sheet — practice combining Power Query and DAX techniques for efficient, maintainable data reshaping in Power BI.