TREATAS and CROSSFILTER
Virtual filters and temporary direction changes
TREATAS(table_expression, target_column, ...) maps a table of values onto existing target columns, in matching number and order. It is useful for intentionally disconnected tables; values absent from the target are ignored. It does not create a persistent model relationship. CROSSFILTER(column1, column2, direction) changes filtering along a relationship that already exists for one evaluation. It is a modifier rather than a scalar or table result. Prefer clear physical relationships when the same mapping is required throughout 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 — Make a disconnected selector affect one measure
Use the Selector[Region] slicer and no Regions slicer or other filters for the first test. The Selector table has North, South and West; West is intentionally absent from Regions.
Selected Region Revenue =CALCULATE([Revenue], KEEPFILTERS( TREATAS(VALUES(Selector[Region]), Regions[Region])))North only returns 104, South only 96, both 200, North and West 104, West only BLANK. Clearing the Selector slicer exposes all three values; after ignoring West, revenue is 200. A deliberately empty selector context (for example a filter equaling a nonexistent selector value) yields BLANK. The ordinary Revenue card remains 200 for all selector choices. With a real Regions slicer set to South and selector North, KEEPFILTERS intersects them, so Selected Region Revenue is BLANK. Without KEEPFILTERS, the virtual filter can replace a filter on the target column. For multiple target columns the table expression must have matching arity and correct positional mapping; avoid mixing identifiers with display labels.
Example 2 — Count products with sales under a region filter
Catalog Products = DISTINCTCOUNT(Products[ProductKey])Products With Sales =CALCULATE([Catalog Products], CROSSFILTER(Sales[ProductKey], Products[ProductKey], Both))With Regions = South, Sales is filtered to L03 and L05. In the default one-way model the filter cannot travel from Sales back to Products, so Catalog Products = 3. The temporary Both direction permits the filtered Sales rows to restrict Products to P01 and P02, so Products With Sales = 2. North yields 3 and all regions yields 3. In this clean model the simpler DISTINCTCOUNT(Sales[ProductKey]) also answers the sold-product question; prefer it if you do not need reverse propagation.
CROSSFILTER directions include None (disable propagation along the named edge), Both and OneWay for an ordinary many-to-one relationship; consult the documented cardinality restrictions for directional many-to-many options. It cannot connect unrelated columns. Changes within nested CALCULATE can conflict; the innermost relevant modifier wins in a conflict. Avoid globally enabling bidirectional relationships just to fix one measure.
Validate access and context before adopting a pattern
A virtual relationship is a calculation technique, not a security boundary. Neither TREATAS nor CROSSFILTER grants access to rows blocked by RLS; relationship changes can be prohibited in a secured topology. The DirectQuery calculated-column/RLS restrictions documented for both functions do not imply all DirectQuery measures are forbidden. Validate on the exact host, storage mode and security configuration before deployment. Test unselected, single, multi, nonexistent and deliberately empty inputs. Never substitute a zero for BLANK without defining the meaning of no matching facts.
Practice — Compare physical and virtual filters
Choose North and West in Selector; also select South in Regions. Predict ordinary Revenue, Selected Region Revenue, Catalog Products and Products With Sales. Then clear Regions and compare both revenue cards. Explain whether a permanent bidirectional relationship is needed. Use the worksheet and admin-only checkpoint values after attempting the task.
Further official reading
Microsoft Learn: treatas function dax · Microsoft Learn: relationship functions dax
These links provide supporting context; the local fixture and its expected results remain unchanged.