RELATED and USERELATIONSHIP
Use model relationships rather than searching each table
RELATED follows a regular many-to-one relationship to return a scalar attribute from the lookup side. It requires row context, such as a calculated column or an iterator. It cannot retrieve a column across a limited relationship. RELATEDTABLE returns the rows related to the current row, often useful on the one side for a count; it does not return a single scalar. USERELATIONSHIP names the endpoints of an existing relationship and chooses that path for a calculation, rather than adding a relationship to the model.
Use the Chapter 24 isolated Import model described in labs/dax-filters-relationships/README.md. Sales has five synthetic lines totaling USD 200, Products has three unique product keys, Regions has North and South, and Dates has one row per day. Relationships filter from dimension to Sales; Dates[Date] to Sales[OrderDate] is active and Dates[Date] to Sales[ShipDate] inactive. The disconnected Selector table has North, South and West. No RLS, no DirectQuery, no other filters unless stated. Create each named measure individually in Desktop; calculated columns go on the specified table. Results are predictions, not observed native execution.
Example 1 — Look up category and count related lines
Create the first calculated column on Sales and the second on Products, separately.
Product Category = RELATED(Products[Category])Related Lines = COUNTROWS(RELATEDTABLE(Sales))For sales lines L01–L05, Product Category is Stationery, Home, Stationery, Travel, Home. For product keys P01, P02, P03, Related Lines is 2, 2, 1 respectively. These are calculated column values in this Import model; report slicers do not recalculate the stored column. A measure such as COUNTROWS(Sales) instead counts lines in its current filter context. Dimension attributes are usually best kept in the dimension: duplicating Category on Sales here is a teaching comparison, not a recommendation to denormalize.
Example 2 — Order revenue versus shipped revenue
Shipped Revenue =CALCULATE([Revenue], USERELATIONSHIP(Sales[ShipDate], Dates[Date]))Put Dates[Date] on matrix rows with [Revenue] and [Shipped Revenue]. Use date filters from Dates, not direct filters on Sales[OrderDate].
| Date (2026) | Order USD | Ship USD |
|---|---|---|
| Jan 5 | 54 | blank |
| Jan 6 | 86 | 54 |
| Jan 7 | 60 | 36 |
| Jan 8 | blank | 110 |
| Total (Jan 5–8) | 200 | 200 |
Revenue uses the active order-date relationship; Shipped Revenue switches to the existing ship-date relationship for its evaluation. Other measures still use the default active path. These sums describe the same five lines from different date perspectives, not two independent revenue streams. If a report needs simultaneous independent order and ship date slicers, use separate role-playing date dimensions with active paths instead.
Relationship and security pitfalls
USERELATIONSHIP accepts existing column endpoints, not computed date expressions. The relationship must exist even if inactive; competing paths and nested modifiers can affect the result. RELATEDTABLE is not a universal join operator for unrelated tables. With RLS, filters do not propagate via inactive relationships merely because USERELATIONSHIP is used; security restrictions may cause a measure to fail. Never use it to attempt to bypass access controls. Design active role-specific security paths and test roles independently. RELATEDTABLE has documented DirectQuery restrictions for calculated columns and RLS; these labs use Import only.
Practice — Explain a date mismatch
For Jan 7, predict the order and ship totals, identify the line IDs included in each, and explain why the difference is not necessarily a data-quality error. Predict the two totals for Jan 6–7 and choose a model design for independent date slicers.
Further official reading
Microsoft Learn: relationship functions dax
These links provide supporting context; the local fixture and its expected results remain unchanged.