Sub topic 4
Creating and Editing Relationships
This chapter assumes you can load tables into Power BI Desktop, know what a fact table and a dimension table are, and have a key column in each table to join on. You will create a relationship, check its properties, and fix the usual problems.
What a relationship does
A relationship links one column in one table to one column in another. When a visual or slicer filters the first table, the filter follows the link and narrows the second table. Without a relationship, a slicer on Product[Category] has no effect on Sales[SalesAmount], and every category shows the same total.
Creating a relationship in the Model view
Power BI can detect relationships automatically on load, but it often guesses wrong or misses some. You can also create them yourself.
- Open the Model view from the left rail.
- Drag the key column from one table onto the matching column in the other, for example
Sales[ProductKey]ontoProduct[ProductKey]. - Power BI draws a line between the tables. A
1at one end and a*at the other show the cardinality. - Double-click the line to open Edit relationship and check its settings.
Using Manage relationships
The Manage relationships dialog lists every relationship in one table. Open it from the Home ribbon. Use it to create a relationship with New relationship, to edit or delete existing ones, and to scan for problems such as an unexpected inactive relationship. This is faster than hunting for lines in a crowded diagram.
The properties you check
Each relationship has these settings in the Edit relationship dialog:
| Setting | What it controls |
|---|---|
| Tables and columns | Which two columns are joined |
| Cardinality | One-to-many, one-to-one, or many-to-many |
| Cross-filter direction | Whether filters flow one way or both ways |
| Make this relationship active | Whether it is the default path between the two tables |
For a standard fact-to-dimension link, the correct setup is many-to-one from Sales to Product, with a single filter direction from Product to Sales. Later chapters explain each setting in depth.
Editing and deleting
To change a relationship, double-click its line and adjust the settings. To remove it, select the line and press Delete, or use Manage relationships. Deleting a relationship does not delete any data. Visuals that depended on it will simply stop filtering across the two tables.
Common errors
- Mismatched data types. A text key cannot join a whole-number key. Change the type in Power Query so both columns match.
- Duplicates on the "one" side. If
Product[ProductKey]repeats, a one-to-many relationship cannot be created. Power BI reports an error or offers many-to-many. Remove the duplicates or choose a better key. - Wrong column pair. Joining on a name column instead of a key can silently mismatch rows with different spellings.
Exercise
You drag Sales[ProductKey] onto Product[ProductKey], but Power BI refuses to create a one-to-many relationship. What is the most likely cause, and where do you fix it?
Show answer
Product[ProductKey] contains duplicate values, so it cannot be the "one" side. Remove or correct the duplicates in the Product table, for example in Power Query, or choose a column that is unique, then create the relationship again.