Sub topic 3
Building a Proper Date Dimension
Assume you know Power BI Model view, basic Power Query, and simple DAX. A date dimension is a table with one row for every calendar date. It provides consistent filtering for years, months, and time periods.
Building a proper date dimension
Create a continuous date table and mark it as a date table. Give it a numeric key that matches the fact table.
Date =
ADDCOLUMNS (
CALENDAR ( DATE ( 2022, 1, 1 ), DATE ( 2025, 12, 31 ) ),
"DateKey", YEAR ( [Date] ) * 10000
+ MONTH ( [Date] ) * 100
+ DAY ( [Date] ),
"Year", YEAR ( [Date] ),
"Month Number", MONTH ( [Date] ),
"Month", FORMAT ( [Date], "MMM" )
)Relate Date[DateKey] to Sales[DateKey] as one-to-many, with filters flowing from Date to Sales. Sort the month name by Month Number.
Flattening dimensions versus snowflaking
A flattened dimension stores related descriptive attributes together. For example, Product can contain product, subcategory, and category columns. A snowflake splits those attributes into separate related tables.
Flattening usually makes filter paths simpler and reduces relationship work. Snowflaking can reduce repeated text and support independently managed hierarchies, but it adds joins and more ways for filters to behave unexpectedly.
> callout note > Prefer a flattened dimension unless the extra tables solve a clear data-management or modeling need.
Shaping source data into a star
In Power Query, duplicate the flat source, keep product attributes for the dimension, and remove duplicate keys. Keep order lines and numeric values in the fact query.
let
Source = SalesFlat,
Columns = Table.SelectColumns(
Source, {"ProductID", "ProductName", "Category"}
),
DimProduct = Table.Distinct(Columns, {"ProductID"})
in
DimProductRole-playing dates
A fact table may contain both order and ship dates. Use one date table with an active order-date relationship and an inactive ship-date relationship.
Sales by Ship Date =
CALCULATE (
[Total Sales],
USERELATIONSHIP ( Sales[ShipDateKey], 'Date'[DateKey] )
)Performance, bridges, and anti-patterns
Star schemas are often smaller and faster because repeated descriptive text stays in dimensions, while the fact table contains keys and numbers. For many-to-many data, use a bridge table with one row per valid pair, such as CustomerProduct.
Avoid one wide table, duplicated date columns used as slicers, unnecessary bidirectional filters, and ambiguous relationship paths. Split the model into facts and dimensions, add a dedicated date table, and use a bridge for many-to-many cases.
Exercise
Which table should filter a sales fact table: Date or Sales?
Show answer
Date should filter Sales through a one-to-many relationship.