Sub topic 2
Creating and Recognizing Inactive Relationships
Assume you know star-schema terms, one-to-many relationships, simple SUM measures, and basic CALCULATE filter context.
Creating and recognizing inactive relationships
A fact table often contains several dates. For example, Sales might contain OrderDate, ShipDate, and DueDate. Each date column can point to the same 'Date'[Date] column. The Date table is then a role-playing dimension because it plays different roles.
Power BI allows only one active relationship between the same two tables when multiple paths could create ambiguous filtering. Usually, the order-date relationship is active. The other relationships remain inactive.
| Relationship | Status | Typical use |
|---|---|---|
| `Sales[OrderDate]` → `'Date'[Date]` | Active | Sales by order date |
| `Sales[ShipDate]` → `'Date'[Date]` | Inactive | Sales by ship date |
In Model view, an inactive relationship appears as a dashed line. Its filters do not propagate during normal visual evaluation.
Recap: `CALCULATE` changes filter context
CALCULATE evaluates a measure after modifying its filter context. A filter context is the set of filters currently applied by visuals, slicers, and DAX expressions.
The base measure uses the active order-date relationship:
Sales Amount =
SUM ( Sales[SalesAmount] )A visual grouped by 'Date'[Year] filters the Date table. That filter travels through the active relationship to Sales[OrderDate].
Activating a relationship with `USERELATIONSHIP`
USERELATIONSHIP is a CALCULATE filter modifier. It temporarily activates an existing relationship for the current calculation. It does not change the model's default active relationship.
Sales Amount by Ship Date =
CALCULATE (
[Sales Amount],
USERELATIONSHIP ( Sales[ShipDate], 'Date'[Date] )
)This measure uses the same Date table, but its filters reach Sales through ShipDate. The relationship must already exist in the model, and both arguments must be the columns on that relationship. Passing unrelated columns produces an error.
> callout note > Use USERELATIONSHIP for a measure-specific date role. The inactive relationship remains inactive for other measures.
Exercise
Why does Sales Amount by Ship Date show ship-date results when the ShipDate relationship is inactive by default?
Show answer
CALCULATE temporarily activates that existing relationship through USERELATIONSHIP, changing how the Date table filters Sales for this measure.