Sub topic 1
Fact and Dimension Tables: The Shape Relationships Serve
Prerequisites
Assume you know how to load tables into Power BI Desktop, recognize rows and columns, use visuals and slicers, and create a basic measure such as SUM ( Sales[SalesAmount] ).
Fact and Dimension Tables
A fact table stores events or measurements. For example, Sales might contain one row per order line, with ProductKey, CustomerKey, OrderDate, and SalesAmount.
A dimension table stores descriptive attributes used to group, filter, or label facts. Product might contain one row per product, with ProductKey, ProductName, and Category. Customer might contain one row per customer.
This arrangement is a star schema. The fact table is in the center, and dimension tables surround it. Relationships connect matching key columns.
A clean star schema usually makes filter behavior easier to predict. Dimension attributes filter the fact table, while measures aggregate values from the fact table.
Finding Your Way Around the Model View
Open Model view to see tables and relationship lines. Select a line to inspect or edit its properties. The Manage relationships dialog lists relationships in a compact table and provides commands to create, edit, or delete them.
Use the diagram to check whether the model has the intended shape. Unexpected direct links between dimensions, duplicate paths, or relationships pointing in the wrong direction often explain incorrect visual results.
Key Columns and Matching Data Types
A relationship needs columns containing compatible keys. The key on the dimension side should identify each row uniquely. The related fact column can repeat that key many times.
The columns must also use compatible data types. A text key such as "1001" does not reliably match a numeric key such as 1001. Clean whitespace, casing, nulls, and invalid values before creating the relationship.
Creating and Editing Relationships
In Model view, drag a key column from one table to the matching column in another table, or choose Manage relationships > New. Confirm the tables, columns, cardinality, and cross-filter direction before selecting OK.
Cardinality: What One and Many Mean
Cardinality describes how many rows on each side can match. Common choices are:
| Cardinality | Meaning |
|---|---|
| One-to-many | One dimension key matches many fact rows |
| One-to-one | Each key matches at most one row on either side |
| Many-to-many | Keys can repeat on both sides |
For a typical Product to Sales relationship, choose One-to-many: Product[ProductKey] is the one side, and Sales[ProductKey] is the many side. Do not choose based only on the current data sample. Choose based on the rule the data is meant to enforce.
Exercise
A Product table has duplicate ProductKey values, while Sales repeats those keys. What should you check first?
Show answer
Check why ProductKey is not unique. Remove duplicates or use the correct product-grain table before creating a one-to-many relationship.