Rules / DAX Expressions

Use the TREATAS function instead of INTERSECT for virtual relationships

warning USE_THE_TREATAS_FUNCTION_INSTEAD_OF_INTERSECT · ported · scope: Measure, CalculationItem

What it checks

Measures and calculation items that call INTERSECT.

Why it matters

INTERSECT is used to push a filter from one table to another when no relationship exists: take the values on one side and intersect them with the other. TREATAS does the same job by treating the first table's values as a filter on the second table's columns, and the engine applies it as a filter, which is much cheaper than materializing both sets and intersecting them.

How to fix it

Replace CALCULATE([Measure], INTERSECT(VALUES(Table2[Key]), VALUES(Table1[Key]))) with CALCULATE([Measure], TREATAS(VALUES(Table1[Key]), Table2[Key])). The SQLBI article in the links covers the pattern.

Quirks

Links

Check a model for this Improve this page