RELATED, USERELATIONSHIP and CROSSFILTER in DAX

How the DAX relationship functions work, RELATED and RELATEDTABLE to follow a relationship from a row, USERELATIONSHIP to use an inactive relationship such as ship date, CROSSFILTER to change the filter direction in one measure, and TREATAS for virtual relationships.

Short answer: relationships carry filters between tables, and four functions control them in DAX. RELATED reads a value from the one side for the current row; RELATEDTABLE returns the matching rows on the many side. USERELATIONSHIP makes an inactive relationship active inside one CALCULATE, for example sales by ship date instead of order date. CROSSFILTER changes the direction of a relationship (one way, both, none) for one calculation. For tables with no relationship at all, TREATAS applies values as a filter.

A model can have only one active path between two tables. A Sales table with an order date, a ship date and a due date has three relationships to the Date table, two of them inactive. These functions are how a measure picks the one it needs.

What does each function do?

FunctionUse inDoes
RELATED ( Table[Column] )row context on the many sidereturns the related value from the one side
RELATEDTABLE ( Table )row context on the one sidereturns the related rows from the many side
USERELATIONSHIP ( Col1, Col2 )CALCULATE filter argumentuses an existing relationship (active or not) for this calculation
CROSSFILTER ( Col1, Col2, Direction )CALCULATE filter argumentsets the filter direction: None, OneWay, Both, OneWay_LeftFiltersRight, OneWay_RightFiltersLeft
TREATAS ( Table, Col )CALCULATE filter argumentapplies values to columns of a table with no relationship
The relationship functions
-- calculated column on Sales: the product's category
Category = RELATED ( 'Product'[Category] )

-- measure: revenue at list price
Revenue at List = SUMX ( Sales, Sales[Quantity] * RELATED ( 'Product'[List Price] ) )

-- calculated column on Customer: number of orders
Order Count = COUNTROWS ( RELATEDTABLE ( Sales ) )

Both need a row context and an existing relationship. RELATED can follow several relationships in a chain (Sales to Product to Product Category), as long as each step goes to the one side.

How do you use an inactive relationship?

Sales has Order Date (active to 'Date'[Date]) and Ship Date (inactive, the dashed line in the model).

Revenue by Ship Date =
CALCULATE (
    [Revenue],
    USERELATIONSHIP ( Sales[Ship Date], 'Date'[Date] )
)

Orders Shipped =
CALCULATE (
    COUNTROWS ( Sales ),
    USERELATIONSHIP ( Sales[Ship Date], 'Date'[Date] )
)
  • By order date
  • By ship date
050100150JanFebMarApr
Revenue in 2026 by month, order date against ship date (thousands)

Inside the CALCULATE, the ship date relationship is used and the order date relationship is ignored for that pair of tables. Microsoft notes that USERELATIONSHIP cannot be used when row-level security is defined for the table that the measure is in, and that the relationship must exist in the model.

How do you change the filter direction?

Relationships filter from the one side to the many side. To count the products a filtered set of customers bought, the filter must go from Sales back to Product:

Products Bought =
CALCULATE (
    DISTINCTCOUNT ( 'Product'[Product Key] ),
    CROSSFILTER ( Sales[Product Key], 'Product'[Product Key], Both )
)

A simpler form that needs no direction change: DISTINCTCOUNT ( Sales[Product Key] ). Use CROSSFILTER ... Both in one measure rather than setting the relationship to both directions in the model, which affects every visual and can make filters ambiguous. None turns a relationship off for the calculation.

What if there is no relationship?

A Budget table at month and category grain cannot relate to the daily Date table directly. TREATAS applies the visible values as a filter:

Budget =
CALCULATE (
    SUM ( Budget[Amount] ),
    TREATAS ( VALUES ( 'Date'[Month] ), Budget[Month] ),
    TREATAS ( VALUES ( 'Product'[Category] ), Budget[Category] )
)

See TREATAS for more.

What goes wrong?

  • RELATED from the one side. It only goes to the one side; use RELATEDTABLE.
  • USERELATIONSHIP without the relationship. It must exist, inactive or active; create it in the model.
  • Both-direction relationships in the model. They spread filters into unexpected tables and can create ambiguous paths; keep them single and use CROSSFILTER in measures.
  • Row-level security. USERELATIONSHIP errors on tables with RLS; consider a second date role table instead.

Where can you check this?

Where do you start?

Add the inactive ship date relationship and a Revenue by Ship Date measure, and put both measures on one chart. The date table post shows how to build the table these relationships point at.

Keep reading

More from the blog.

Every post

Next

Building this? Say hello.

A question about this post, a pattern you would build differently, or the next thing you want written out: Behnia reads every message.