Sub topic 6
Activating a relationship with USERELATIONSHIP
This chapter assumes you can build a star schema in Power BI or an Analysis Services Tabular model. It also assumes you know what an active and an inactive relationship are, and that you can read a measure that uses CALCULATE. The model has a Sales fact table and a 'Date' dimension. Sales[OrderDate] has the active relationship to 'Date'[Date]. Sales[ShipDate] has an inactive one.
USERELATIONSHIP lets a single calculation switch to an inactive relationship without changing the model. This chapter covers the syntax, what the engine does with it, the rules it enforces, and the errors you are most likely to hit.
What USERELATIONSHIP does
An inactive relationship exists in the model but does not filter anything by default. A report slicer on 'Date'[Year] filters Sales through the active relationship only. A measure that needs the same slicer to act on ship dates must turn the inactive relationship on.
USERELATIONSHIP does that for the duration of one CALCULATE. It is a filter modifier, like ALL or KEEPFILTERS. It does not return a table or a value. It tells CALCULATE which relationship to use when it propagates filters while evaluating the expression.
Nothing is changed permanently. The model's active and inactive flags stay as you set them. Other measures and visuals keep using the active relationship.
Syntax and argument rules
USERELATIONSHIP ( <columnName1>, <columnName2> )Both arguments are fully qualified column references. By convention, the first is the fact table column (the many side) and the second is the dimension column (the one side), as in Sales[ShipDate] and 'Date'[Date].
- The two columns must be the two ends of an existing relationship in the model.
USERELATIONSHIPcannot create a relationship. - The relationship may be active or inactive. Naming an active one is allowed and has no visible effect.
- You cannot pass a table, an expression, or a column made by a function. Only plain column references work.
- The function is only valid as a filter argument of
CALCULATEorCALCULATETABLE. Other contexts, such as a bare measure body or a calculated column, return an error.
A worked example
Here is a small Sales table. One order has not shipped yet, so its ShipDate is blank.
| OrderID | OrderDate | ShipDate | SalesAmount |
|---|---|---|---|
| 1 | 2025-12-28 | 2026-01-03 | 100 |
| 2 | 2026-01-05 | 2026-01-06 | 50 |
| 3 | 2026-01-20 | 2026-02-02 | 80 |
| 4 | 2026-02-10 | (blank) | 70 |
The base measure follows the active relationship, so it reports by order date:
Sales Amount = SUM ( Sales[SalesAmount] )The ship-date version wraps the same measure in CALCULATE and activates the other relationship:
Sales Amount by Ship Date =
CALCULATE (
[Sales Amount],
USERELATIONSHIP ( Sales[ShipDate], 'Date'[Date] )
)Place both measures in a matrix with the month on rows and you get this:
| Month | Sales Amount | Sales Amount by Ship Date |
|---|---|---|
| 2025-12 | 100 | (blank) |
| 2026-01 | 130 | 150 |
| 2026-02 | 70 | 80 |
| Total | 300 | 300 |
January by ship date is 150 because orders 1 and 2 both shipped that month. Order 1 was placed in December but counts toward January here. The Total row shows 300 for both measures, even though the monthly ship-date values add up to 230. The Total row has no filter on 'Date', so no relationship is used and order 4 (blank ship date) is included. The Pitfalls chapter returns to this in detail.
You can check the numbers with a DAX query. It assumes your 'Date' table has Year and Month Number columns:
EVALUATE
SUMMARIZECOLUMNS (
'Date'[Year],
'Date'[Month Number],
"Ordered", [Sales Amount],
"Shipped", [Sales Amount by Ship Date]
)
ORDER BY 'Date'[Year], 'Date'[Month Number]What happens during evaluation
Evaluation follows the CALCULATE order you already know. First, the existing filter context is read. Then the CALCULATE arguments are applied. Relationship modifiers are applied before the filter arguments. Finally the expression is evaluated.
Two points follow from this order.
- The activated relationship replaces the active one for that pair of tables. Only one relationship between
Salesand'Date'can filter at a time. When ship date is in use, the order-date relationship does not filter, so a slicer on'Date'[Year]stops constraining order date. - The change reaches everything evaluated inside the
CALCULATE. A measure you reference, such as[Sales Amount], is evaluated under the modified relationships. That is why you do not rewrite the aggregation.
Filters already applied to 'Date' columns still pass through as normal filter context. They reach Sales through the new relationship. Filters on Sales[OrderDate] itself are not affected, because they are direct filters on a fact column.
Using more than one relationship at once
You can pass several USERELATIONSHIP calls in one CALCULATE, as long as each names a different relationship. This is common when a model has more than one dimension with an inactive link. In this example, the Sales table also has a due date, and the Customer table has an inactive link to Sales[ReferrerKey] besides its active CustomerKey link:
Sales by Due Date and Referrer =
CALCULATE (
[Sales Amount],
USERELATIONSHIP ( Sales[DueDate], 'Date'[Date] ),
USERELATIONSHIP ( Sales[ReferrerKey], Customer[CustomerKey] )
)Do not name two different relationships between the same pair of tables in one CALCULATE, such as both ship date and due date to 'Date'. Only one of them can be active, so the combination is ambiguous and the result is not reliable. Use two separate measures instead.
Combining with other filter arguments
Filter arguments of CALCULATE can sit beside USERELATIONSHIP in any order. The relationship is selected first, then the filter arguments are evaluated and applied through the selected relationship. That is why a year-to-date filter works on ship date:
Shipped Sales YTD =
CALCULATE (
[Sales Amount],
USERELATIONSHIP ( Sales[ShipDate], 'Date'[Date] ),
DATESYTD ( 'Date'[Date] )
)DATESYTD returns a set of dates from the 'Date' table. Those dates then filter Sales through ship date, because that is the relationship in use. The next chapter covers time intelligence in more detail.
A useful comparison measure builds on both versions:
Ordered Not Yet Shipped =
[Sales Amount] - [Sales Amount by Ship Date]Use it in a visual with a date filter, not in the Total row. The Total row would show 0 for the sample data, because no date filter applies there.
Rules and limits to remember
- Needs an existing relationship. If no relationship connects the two columns, the measure fails with an error. Creating the inactive relationship in the model comes first.
- One role per calculation. A
CALCULATEshould switch a given pair of tables to one relationship only. - Applies to the expression, not the visual. Visuals that need ship date must use a measure with
USERELATIONSHIP. Putting'Date'[Month]on an axis still filters by order date for any measure that does not switch roles. - Cross-filter direction still counts. The relationship you activate keeps its own cross-filter direction and cardinality settings. A both-direction setting on an inactive relationship takes effect when it is activated.
- Row-level security can block it. Microsoft's documentation notes that
USERELATIONSHIPreturns an error when row-level security is defined on a table involved in the relationship. Check this before you rely on it in a secured model.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Error that the relationship does not exist | The two columns are not joined by a relationship in the model | Create the relationship between them. It can be inactive. |
| Error that the function can only be used in a `CALCULATE` filter | `USERELATIONSHIP` placed in a measure body, a column, or a non-filter position | Wrap the expression in `CALCULATE` and pass `USERELATIONSHIP` as a filter argument. |
| Measure shows the same numbers as the order-date measure | The relationship named is the active one, or the wrong column pair was used | Check that the first argument is `Sales[ShipDate]`. |
| Ship-date months add up to less than the Total | Rows with a blank `ShipDate` appear only when no date filter applies | Expect this. Show unshipped rows in a separate measure if needed. |
| Wrong results after adding a second `USERELATIONSHIP` for the same tables | Two relationships between the same tables in one `CALCULATE` | Split into separate measures. |
Exercises
Exercise
A matrix shows month on rows. Your measure Sales Amount by Ship Date shows 150 for January 2026, but a colleague's measure SUM ( Sales[SalesAmount] ) shows 130 for the same month. Both are correct. Explain why the two values differ.
Show answer
The colleague's measure uses the active relationship, so January includes orders placed in January (orders 2 and 3, 50 + 80 = 130). Your measure uses USERELATIONSHIP to filter by ship date, so January includes orders shipped in January (orders 1 and 2, 100 + 50 = 150). Order 1 was placed in December, which is why it counts for January only under the ship-date measure.
Exercise
Write a measure called Sales Amount by Due Date that sums Sales[SalesAmount] by due date, assuming an inactive relationship exists between Sales[DueDate] and 'Date'[Date]. Then say what happens if the relationship does not exist.
Show answer
Sales Amount by Due Date =
CALCULATE (
SUM ( Sales[SalesAmount] ),
USERELATIONSHIP ( Sales[DueDate], 'Date'[Date] )
)
If no relationship connects Sales[DueDate] and 'Date'[Date], the measure returns an error. USERELATIONSHIP can only select a relationship that is already in the model, so you must create it first, as an inactive relationship.
Exercise
In the sample data, the matrix shows 300 in the Total row for Sales Amount by Ship Date, but the three months add up to 230. Why, and which order accounts for the difference?
Show answer
The Total row has no filter on the 'Date' table, so no relationship is used to filter Sales, and every row is summed, including order 4. Order 4 has a blank ShipDate, so it matches no month and never appears in a monthly ship-date value. Its amount, 70, is the difference between 300 and 230.