Sub topic 14
One-to-one relationships
This chapter assumes you can create a relationship in the Model view and that you know what cardinality and cross-filter direction mean from the earlier chapters. It covers when a one-to-one relationship is the right choice, how it behaves, and what usually goes wrong.
What a one-to-one relationship is
In a one-to-one relationship, each value in the key column of table A matches at most one row in table B, and the reverse is also true. Both key columns must contain unique values. Neither table is the "many" side.
Power BI chooses this cardinality automatically when it finds unique values in both columns while you create the relationship. You can also select it by hand in the Edit relationship dialog.
The two tables then behave like one logical table split in two. Filtering either table filters the other.
Defaults that differ from one-to-many
A one-to-one relationship differs from a one-to-many relationship in three ways.
| Behavior | One-to-many | One-to-one |
|---|---|---|
| Uniqueness required | Only on the "one" side | On both sides |
| Default cross-filter direction | Single, from "one" to "many" | Both |
| `RELATED` usable from | The "many" table | Either table |
The default direction of Both is safe here. Each row has at most one partner, so a filter cannot fan out and double count. This is why the bidirectional risks from the earlier chapter mostly do not apply to a single one-to-one link. They can still matter when the pair is part of a longer chain, which is covered below.
When to use one
Most one-to-one relationships can be avoided. Merging the two tables in Power Query usually gives a simpler model. Keep them separate only when you have a reason:
- Different sources or refresh schedules. The profile data comes from a CRM and the core attributes come from a data warehouse.
- Wide tables. Seldom-used columns are moved out so the field list stays readable.
- Sensitive columns. Salary, health, or contact details sit in their own table. This lets you hide the whole table, or control access with row-level security (RLS) roles.
- A shared extension table. Several dimensions each have one extension row, and you want to keep the extension logic separate.
If none of these apply, merge the tables. A merged table has one fewer relationship to maintain and no uniqueness constraint to break.
Worked example
Suppose Customer holds CustomerKey, Name, and Country. A second table, CustomerProfile, holds CustomerKey, Segment, and LoyaltyTier. Each customer appears once in each table.
- Open the Model view.
- Drag
Customer[CustomerKey]ontoCustomerProfile[CustomerKey]. - Double-click the line to open Edit relationship.
- Confirm that Cardinality reads One to one (1:1) and that Cross-filter direction reads Both.
- Keep Make this relationship active selected, then choose Save.
The line shows a 1 at each end and a double arrow. A slicer on CustomerProfile[Segment] now filters Customer, and through Customer it also filters Sales.
Because the tables are linked, RELATED works from either side. The first column below is added to Customer. The second is added to CustomerProfile:
Segment = RELATED ( CustomerProfile[Segment] )Country = RELATED ( Customer[Country] )Each is a calculated column. Because each row has exactly one partner, neither column needs an aggregation. You would only reach for RELATEDTABLE here to count or test for the presence of a partner row. It returns a table of at most one row.
Checking uniqueness before you relate
Power BI will not let you set a one-to-one cardinality if either column contains duplicates. Check first. This measure returns zero when the key is unique:
Duplicate Customer Keys =
COUNTROWS ( Customer ) - DISTINCTCOUNT ( Customer[CustomerKey] )Put the measure in a card visual. Create the same measure for the other table by changing the table and column names. A blank key counts as a value for DISTINCTCOUNT, so a result of zero also means the column has at most one blank row.
Failure modes
The cardinality changes on its own. If you create the relationship while one column has duplicates, Power BI picks one-to-many or many-to-many instead. Fix the data, then edit the relationship.
Refresh breaks later. Suppose you set one-to-one and new source data introduces a duplicate key. The refresh fails with an error about duplicate values in the key column. The model is correct, and the data has changed. Find the duplicate rows in the source, or add a deduplication step in Power Query.
Unmatched keys. If a customer exists in Customer but not in CustomerProfile, a visual that uses columns from CustomerProfile shows only the customers that have a profile. A slicer on Segment therefore hides customers with no profile. Compare the row counts of the two tables to see whether this applies to your data.
Both-direction filtering inside a chain. The one-to-one link filters in both directions. If CustomerProfile is also related to another table, a filter can reach places you did not intend. Power BI may then report an ambiguous path. Setting the one-to-one link to Single direction removes the ambiguity, provided you only need filters to flow from one table to the other.
Treating one-to-one as a fact-to-dimension link. A fact table with one row per entity is a sign of a modeling problem. The Sales table should relate many-to-one to Customer, not one-to-one. If your fact table really has one row per customer, it is a dimension.
Decision checklist
- Do both key columns hold unique values? If not, one-to-one is not valid.
- Do you need the tables separate for security, source, or size? If not, merge them.
- Is the pair part of a longer chain? If so, check whether Both direction creates an ambiguous path.
- Do the two tables have the same set of keys? If not, decide how unmatched rows should appear in visuals.
Exercise
You relate Customer[CustomerKey] to CustomerProfile[CustomerKey]. Power BI creates a one-to-many relationship instead of one-to-one. What is the most likely cause, and how do you check it?
Show answer
CustomerKey is not unique in one of the tables, so Power BI cannot assign a one-to-one cardinality. Check each table with COUNTROWS ( Customer ) - DISTINCTCOUNT ( Customer[CustomerKey] ), and the same for CustomerProfile. A result above zero means there are duplicate (or repeated blank) keys. Remove or merge the duplicate rows, then edit the relationship and set it to one-to-one.
Exercise
A slicer on CustomerProfile[Segment] hides customers who have no row in CustomerProfile. Which behavior of the relationship explains this, and what are two ways to avoid it?
Show answer
The relationship filters in both directions, and a customer with no matching profile row has no Segment value to match the slicer selection, so it is filtered out. You can avoid it by adding a profile row (for example with a "Unknown" segment) for every customer, or by merging the profile columns into Customer in Power Query with a left join and replacing nulls with a default value.