Sub topic 12
Relationships, cardinality, and filter direction
This chapter assumes you have loaded at least two related tables with Get data and can open Model view from the left-hand view switcher. You should also know what a primary key and a foreign key are in a spreadsheet or database. Here you will learn how relationships connect tables, what cardinality and cross-filter direction mean, and which mistakes cause wrong totals.
What a relationship does
A relationship is a link between one column in one table and one column in another table. It tells Power BI how to carry a filter from one table to the other. Without a relationship, a slicer on a Customers table cannot change the totals computed from a Sales table. The two tables simply do not know about each other.
A relationship does not merge tables or copy data. It only defines the path a filter follows. This is why a model with several small tables is usually faster and clearer than one wide table.
Power BI Desktop often creates relationships for you when you load data. It looks for columns with matching names and compatible data types. Auto-detection is a convenience, not a guarantee, so always check the result in Model view.
Reading a relationship in Model view
In Model view, each table is a box with its columns listed. A relationship is a line between two boxes. The line carries three pieces of information:
- Cardinality markers at each end:
1or*. - An arrowhead in the middle of the line, showing the cross-filter direction.
- Line style: a solid line is an active relationship, and a dashed line is an inactive one.
To edit a relationship, double-click the line. The Edit relationship dialog opens. It shows a preview of both tables, the two selected columns, the cardinality, the cross-filter direction, and a checkbox to make the relationship active. You can also create one by dragging a column from one table onto a column in another, or by choosing Manage relationships on the Home tab.
Cardinality
Cardinality describes how many rows on each side can match. Power BI offers four options.
| Cardinality | Meaning | Typical use |
|---|---|---|
| One to many (1:*) | One row on the "one" side matches many rows on the "many" side. | A `Customers` table related to a `Sales` table. This is the most common type. |
| Many to one (*:1) | The same as one to many, with the tables in the opposite order. | The same case, depending on which table you select first. |
| One to one (1:1) | Each row matches at most one row in the other table. | Splitting a wide table into two parts that share a key. |
| Many to many (*:*) | Rows on both sides can match several rows. | Special cases where neither column is unique. |
The "one" side must contain unique values in the key column. A CustomerID column in Customers should list each customer once. The "many" side can repeat the value, as Sales does when one customer places many orders.
Why uniqueness matters
If you ask for one to many but the "one" column contains duplicates, Power BI cannot create the relationship as requested. It shows an error and suggests many to many. Do not accept that suggestion automatically. Duplicate keys usually point to a data problem, such as a repeated customer row or trailing spaces in text. Fix the data in Power Query Editor first.
Many to many relationships also make totals harder to reason about, because a single row can match several rows on the other side. Use them only when you understand why neither side is unique. A common better design is to add a small table of unique values and relate both tables to it.
Cross-filter direction
Cross-filter direction decides which way filters travel across the relationship.
- Single: filters flow from the "one" side to the "many" side only. Selecting a customer filters
Sales, but selecting a sale does not filterCustomers. - Both: filters flow in either direction.
Single is the default for one to many relationships, and it is the right choice most of the time. The arrowhead on the line points in the direction filters travel. With Both, the line shows arrowheads in both directions.
A worked example
Suppose Customers has a Country column, and Sales has SalesAmount. With a single-direction relationship from Customers to Sales, a bar chart that shows Country on the axis and the sum of SalesAmount as values works as you expect. Each country filters the sales rows that belong to its customers.
Now suppose you add a slicer based on Sales[Channel] and a table visual that lists Customers[Name]. With single direction, the slicer cannot filter the customer list, because the filter would have to flow from the "many" side to the "one" side. Every customer still appears. Switching the relationship to Both makes the list show only customers who bought through the selected channel.
You can then define measures to check what each filter does. These two measures come from the model used in the earlier chapters:
Total Sales = SUM(Sales[SalesAmount])Order Count = COUNTROWS(Sales)Place either measure in a table visual next to Customers[Name] and change the slicer. Compare the results under Single and Both to see the effect.
Risks of Both
Both is not a free upgrade. It has costs:
- Ambiguity. When several tables are connected with Both, Power BI may find more than one path between two tables. It then deactivates one relationship or produces results that are hard to explain.
- Performance. Filters travel further, so queries can do more work on large models.
- Surprising totals. Visuals can change when you add an unrelated slicer, because filters now pass through paths you did not plan for.
Prefer Single and add Both only for a specific need. For a one-off need, a DAX measure can often apply the reverse filter for just one calculation, which keeps the model simple.
Active and inactive relationships
Between any two tables, only one relationship can be active at a time. An active relationship filters automatically. An inactive relationship shows as a dashed line and does nothing until a DAX measure explicitly uses it.
The usual case is a Sales table with both an OrderDate and a ShipDate, each related to one Date table. One relationship is active, normally on OrderDate, and the other is inactive. Power BI may also deactivate a relationship on its own when activating it would create ambiguous paths.
Common errors and how to fix them
| Symptom | Likely cause | Fix |
|---|---|---|
| Every row shows the same total | No relationship, or a relationship on the wrong columns | Open Model view and check that the line exists and joins the right keys. |
| The relationship cannot be created as one to many | Duplicate or blank values in the "one" column | Remove duplicates in Power Query Editor, or choose a different key column. |
| Related columns do not match | Different data types, such as text and whole number | Set both columns to the same type in Table view or Power Query Editor. |
| Matches missing because of spacing or case | Trailing spaces or inconsistent text in keys | Clean the text in Power Query Editor with Trim. |
| A blank row appears in a slicer | Values in the "many" table with no match in the "one" table | Add the missing rows to the "one" table or correct the key values. |
| A relationship is dashed | It is inactive | Check "Make this relationship active", or use it in a measure. |
The blank row case deserves attention. When Sales contains a CustomerID that does not exist in Customers, Power BI groups those rows under a blank customer. This is not a bug. It is a signal that your keys are incomplete.
Checking your work
After you create or edit a relationship, verify it with a quick test.
- Switch to Report view and add a table visual with a column from the "one" table and a measure such as
Total Sales. - Confirm that each value differs by row. If every row has the same number, the filter is not flowing.
- Add a slicer from the "many" table. Check whether the "one" table's list responds, and decide whether that is the behavior you want.
- Return to Model view and read the line again. Confirm the markers, the arrow, and whether it is solid.
Summary of decisions
- Use one to many with Single direction as the default.
- Keep key columns unique on the "one" side and the same data type on both sides.
- Treat a many to many suggestion as a prompt to inspect your data.
- Use Both only for a clear, tested need.
- Check the line, markers, and arrowhead in Model view after every change.
Exercise
A Customers table is related to a Sales table with a one to many relationship and Single direction. You add a slicer on Sales[Channel] and a list of Customers[Name], but the list still shows every customer. Why does this happen, and what are two ways to address it?
Show answer
With Single direction, filters flow only from the "one" side (Customers) to the "many" side (Sales). A slicer on Sales cannot filter Customers, so every customer stays visible. You can change the relationship to Both so filters also flow from Sales to Customers, accepting the risks of ambiguity and slower queries. Or you can keep Single direction and write a DAX measure that applies the reverse filter for only the visual that needs it.
Exercise
Power BI refuses to create a one to many relationship between Products[ProductID] and Sales[ProductID] and suggests many to many. What should you check first?
Show answer
Check whether Products[ProductID] contains duplicate or blank values, since the "one" side must be unique. Look for repeated product rows, trailing spaces, or inconsistent text. Clean or deduplicate the data in Power Query Editor rather than accepting many to many.