Intermediate: Group, Unpivot and Read SQL Safely
Understand it in simple language
A clean table often needs a different shape. Split Column separates structured text, Replace Values corrects known values, Conditional Column labels rows, Group By aggregates at an explicit grain, and Unpivot turns repeated month columns into rows. Keep detail when later analysis needs it.
SQL is useful for understanding the source. SELECT chooses fields, WHERE filters rows, GROUP BY aggregates and JOIN combines tables. A join can duplicate values just like a Power Query merge.
Do it step by step
- In Power Query, duplicate the clean Sales query for an experiment; do not replace the fact table.
- Choose Add Column > Conditional Column. Name it LineBand; if Quantity is greater than or equal to 3, return Bulk, otherwise Single.
- Add a Custom Column LineRevenue with
[Quantity] * [UnitPrice]. - Choose Home > Group By > Advanced. Group by Region; add Revenue as Sum of LineRevenue and Lines as Count Rows.
- Expect North 1250/two lines and South 1050/two lines.
- For an unpivot exercise, use Enter Data to create Region, Jan and Feb columns. Select Region > Unpivot Other Columns; rename Attribute to Month and Value to Revenue.
- On an approved SQL training source, run a read-only query such as
SELECT Region, SUM(Quantity * UnitPrice) AS Revenue FROM Sales GROUP BY Region. Reconcile against the same cleaned source.
Check your result
Can you explain the grain before and after Group By? It changes from order line to region.
If something goes wrong
Do not aggregate the only copy of your order-line fact table. The grouped result cannot answer order-level drillthrough questions.
Practice data and learning method
Industry practice collection: downloadable retail, finance, HR and operations datasets, dictionaries, full walkthroughs and answer sheets. The cases contain multiple years, multiple related tables, deliberate data defects and known-answer checks. Progress from the small foundation files below to these cases; do not reuse the foundation totals for the larger datasets.
Download Sales.csv, Products.csv, and the dataset guide. These files contain synthetic training data, not real customers. Use the Power BI virtual labs for guided browser practice. Each lab states its supported operations. Then repeat the procedure above in the actual Microsoft tools and save evidence of your result. Try another filter or an intentionally incorrect setting and explain what changed before moving on.
Guided practicals for this topic
Virtual lab · Microsoft Power BI · 35 min
Unpivot a real two-year budget file
Hands-on finance case: load the downloadable CSV tables, perform the actions, inspect the full-data result and reconcile it. Includes a paired Desktop procedure.
Continue learning from Microsoft
Power BI documentation · DAX reference · Power Query M reference · Power BI analyst skills map. Features, licensing, menus and availability can change; check the relevant official page for your environment.
Practise this topic
Hands-on virtual lab
Apply what you just read in a realistic, guided simulation. Free with a verified account.
Create a free account to track your progress and unlock virtual labs.