Sub topic 3
Why only one relationship between two tables can be active
This chapter assumes you know star schemas, one-to-many relationships, simple DAX measures such as SUM, and the basics of CALCULATE and filter context. It explains why a model allows only one active relationship between two tables, and what Power BI does when you try to create a second one.
The situation
A Sales fact table often has several date columns: OrderDate, ShipDate, and DueDate. Each one can relate to 'Date'[Date]. That gives three candidate relationships between the same two tables. The Date table plays a different role in each one, which is why it is called a role-playing dimension.
The model lets all three exist, but only one can be active at a time. The other two are inactive. Inactive relationships stay in the model and show as dashed lines in model view, but they do not filter anything unless a calculation asks for them.
The ambiguity problem
Suppose all three relationships were active. A user places 'Date'[Year] on a visual with SUM ( Sales[SalesAmount] ). The engine now has to decide how the year filter reaches Sales:
- through
OrderDate, so the measure shows sales by year ordered, - through
ShipDate, so it shows sales by year shipped, - through
DueDate, so it shows sales by year due, - or through all three at once, so only rows where the three years match are counted.
Nothing in the measure or the visual says which one is meant. The model needs exactly one answer for how a filter on 'Date' reaches Sales, so it permits only one active relationship between any pair of tables.
The rule also covers indirect paths. If the model had two different chains of active relationships connecting the same two tables, the engine could not pick between them. Power BI blocks that as well, or it deactivates one relationship for you.
What Power BI does when you add a second relationship
When you create a relationship between two tables that already have an active one, Power BI creates the new one as inactive. The Edit relationship dialog shows the Make this relationship active check box cleared and unavailable until you deactivate the existing one.
If you load a model where several date columns were auto-detected, Power BI usually activates the first relationship it creates and marks the rest inactive. You can check which one it chose by looking for solid and dashed lines in model view.
You can switch which relationship is active. If you set the ShipDate relationship to active, Power BI turns the OrderDate one off. Every measure that relied on the default path then changes meaning, because "Sales Amount" now reports by ship date.
This is the reason to choose the active relationship deliberately. The active one is the default date role for every visual and every measure that does not say otherwise. Most models pick the column that users think of as "the date of the sale", usually the order date.
A measure shows the rule at work
With the order-date relationship active, this base measure reports sales by order date:
Sales Amount = SUM ( Sales[SalesAmount] )Place 'Date'[Year] and [Sales Amount] in a table. Each row shows the sales whose OrderDate falls in that year. The ship-date and due-date relationships have no effect on the numbers, even though they exist.
To get sales by ship date you must tell the engine to use the inactive relationship for one calculation. That is the job of USERELATIONSHIP, covered in a later chapter. The point here is that the single-active rule is what makes the default behavior predictable. Without it, the same measure could return different numbers depending on which path the engine happened to choose.
Common mistakes
- Trying to activate two at once. Power BI Desktop refuses, and tells you to deactivate the other one first. In a Tabular model built with other tools, the deployment fails with an ambiguity error.
- Assuming inactive means unused. An inactive relationship still exists in the model. A measure can activate it, and Power BI will not delete it.
- Changing the active relationship to fix one report. This changes every measure that uses the default path. Fix the one measure instead.
- Forgetting which one is active. A report can look correct but be built on the wrong date role. Check model view before you debug the DAX.
Exercise
A Sales table has OrderDate and ShipDate, both related to 'Date'[Date], and both relationships are set to active in a modeling tool that does not enforce the rule. A visual shows SUM ( Sales[SalesAmount] ) by 'Date'[Year]. Why is this a problem, and how does the model avoid it?
Show answer
A year filter on 'Date' could reach Sales through either column, or through both at once, so the result is ambiguous. The model avoids this by allowing one active relationship between two tables. The other relationship is inactive and has no effect unless a measure activates it, for example with USERELATIONSHIP.