Multi-grain ETL
Build a model that respects three grains
The intermediate capstone answers whether sales meet budget and whether stock is complete. Sales are individual order lines, budget is one amount per month and category, and inventory is one product snapshot per date. Import the original fictional files in labs/multi-grain-capstone/ separately. Use the same dimensions, not a join of fact rows. All money is synthetic USD, cost is positive, and stock is units.
Define keys and filter paths
Create Month (one row per month), Date (one row per day with MonthStart), Category (one row per category), and Product (one row per product with CategoryID). Use active single-direction one-to-many relationships Month → Date → Sales and Inventory, Category → Product → Sales and Inventory, and Month → Budget, Category → Budget. Each relationship uses matching keys and types. Use the supplied full 2025 calendar; restrict the report to January and February in Month. Mark Date as a date table for later classic time intelligence. Hide fact keys and fields from report authors; only expose dimension slicers and explicit measures. This controlled snowflake has one path from each dimension to each fact; do not add a direct Month-to-Sales or Category-to-Sales link.
Example 1 — Reusable ingestion
Create a blank function query named ReadTypedCsv with the supplied ReadTypedCsv.m. It promotes headers, checks the exact ordered schema, applies types with en-US culture, and fails on conversion errors. Use a text parameter Root containing the local lab folder (no trailing slash).
let Types = {{"LineID", type text}, {"Date", type date}, {"ProductID", type text}, {"Revenue", Currency.Type}, {"Cost", Currency.Type}}, Jan = ReadTypedCsv(File.Contents(Root & "/sales-jan.csv"), Types), Feb = ReadTypedCsv(File.Contents(Root & "/sales-feb.csv"), Types), Combined = Table.Combine({Jan, Feb})in CombinedExpected: six unique order lines, revenue 470, cost 290. Apply the same function to the other files with their respective type lists in the lab. Reject the refresh on invalid keys, blank amounts or repeated grain; do not remove duplicates silently. M native execution is not run.
Example 2 — Prove the join is unsafe
January category A has two sales lines (100 and 50) and one budget row (140). Joining on month/category repeats the budget on each line, giving 280 rather than 140. February A repeats 160 likewise. The correct category A budget across both months is 300. Pre-aggregate sales to month/category only for an independent reconciliation, never replace the detailed sales fact with the joined result. The supplied oracle tests both totals.
Quality gates before loading
Verify every primary key is nonblank and unique, every foreign key resolves, every budget month/category pair is unique, and every inventory date/product pair is unique. Expected source counts: 3 + 3 sales lines, 4 budgets, 5 snapshots, 3 products, 2 categories, 12 months and 365 dates. Budget coverage is complete for Jan/Feb. Inventory intentionally lacks February A2: preserve the missing row as an exception, not a zero. Do not approve out-of-scope months as complete.
Practice — Trace a failed refresh
Make a disposable copy of January sales and duplicate L1. Predict how both the row count and total revenue change, and identify the uniqueness check that should stop loading. Restore the original and reconcile again. Document the source-to-query mapping in the lab worksheet. Microsoft guidance: https://learn.microsoft.com/en-us/power-bi/guidance/relationships-many-to-many; https://learn.microsoft.com/en-us/power-query/custom-function; https://learn.microsoft.com/en-us/power-query/combine-files-overview; https://learn.microsoft.com/en-us/power-bi/guidance/model-date-tables