Sub topic 12
Relationships, cardinality, and filter direction
This chapter assumes you have loaded at least two related tables in Power BI Desktop and have opened Model view. You should know that Model view shows each table as a box and each relationship as a line between boxes.
What a relationship does
A relationship links a column in one table to a column in another. Once the link exists, a filter applied to one table also narrows the rows of the other. For example, selecting one product in a slicer limits the Sales table to that product's rows.
Relationships are why you can drag Product[Category] and Sales[SalesAmount] into the same visual without writing a join.
Creating and editing a relationship
Power BI Desktop often detects relationships when you load data. To add or fix one:
- Switch to Model view.
- Drag a column, such as
ProductIDin Sales, onto the matching column in Product. - Double-click the new line to open the Edit relationship dialog.
- Check the two columns, the cardinality, and the cross-filter direction, then select Save.
You can also use Manage relationships on the Home tab to see every relationship in one list.
Cardinality
Cardinality describes how many rows on each side can share a key value.
| Cardinality | Meaning | Typical use |
|---|---|---|
| Many-to-one (`*:1`) | Many rows in the first table match one row in the second | Sales to Product |
| One-to-one (`1:1`) | Each value appears once in both tables | Splitting a wide table |
| Many-to-many (`*:*`) | Values repeat in both tables | Rare cases with no clean lookup table |
The "one" side should hold unique keys. A Product table with one row per product is a lookup table, and Sales is a fact table with one row per transaction. Prefer this layout.
Cross-filter direction
Cross-filter direction sets which way filters travel across the relationship.
- Single: filters flow from the "one" side to the "many" side. Selecting a product filters Sales. This is the default and the safest choice.
- Both: filters flow in both directions. Selecting rows in Sales can also narrow the Product table.
Checking a relationship with a measure
Use a measure to confirm that filters reach the fact table. This one counts Sales rows:
Order Count = COUNTROWS(Sales)Place Product[Category] and Order Count in a table visual. If every category shows a different, sensible count, the relationship works. If every category shows the same total, the relationship is missing or inactive.
Common errors
- Repeated totals in a visual. No active relationship connects the tables. Create one in Model view.
- Inactive relationship. A dashed line means the relationship exists but is not used by default. Only one active path can exist between two tables.
- Duplicate keys on the "one" side. Power BI cannot create a one-to-many relationship if the key repeats. Clean the data or choose a different column.
- Mismatched data types. A text
ProductIDwill not match a whole-numberProductID. Fix the types in Table view.
Exercise
A table visual shows the same Order Count for every product category. Name two likely causes in the model.
Show answer
No active relationship exists between Product and Sales, or the relationship is inactive (a dashed line). A mismatch in column data types that prevented the relationship from being created is also possible.