<!-- https://learnsql.cpetoday.com/functions/dax/treatas -->
# TREATAS

Language: DAX
Category: Relationships and lookup
Syntax: TREATAS(<expression>, <column> [, <column> ...])
Summary: Uses the values of a table as filters on columns in another table, with no relationship in the model.
Returns: A table. Used as a filter inside CALCULATE, or as a table.
Level: Advanced
Related: VALUES, CALCULATE, USERELATIONSHIP, CROSSFILTER, RELATED, LOOKUPVALUE

## What it does
TREATAS takes the values of one table and applies them as filters on a column in another table, as though the two were related. Use it when two tables are not connected in the model: a budget kept by store name, a mapping table, or a selection that must filter a different table. It does not change the model. The filter follows the column you name as the target.

## Syntax and arguments
- **expression**: a table of values, such as `VALUES(Budget[StoreName])` or a table constructor.
- **column**: the column that receives the filter. The number of columns must match the expression, and the data types should match.

## Example
A budget kept in its own table, keyed by store name. The budget should follow the stores on the page. This assumes a Budget table with a StoreName column, which is not part of the Contoso sample.

```dax
Budget for Visible Stores =
CALCULATE (
    SUM ( Budget[Amount] ),
    TREATAS ( VALUES ( Stores[StoreName] ), Budget[StoreName] )
)
```

The store names visible on the page become filters on Budget[StoreName]. Each row shows the budget for its store, with no relationship needed.

## Example: a second use
Sales for only the product categories that have a budget line. The budget uses category names, and the product list uses the same names.

```dax
Sales for Budgeted Categories =
CALCULATE (
    [Total Sales],
    TREATAS ( VALUES ( Budget[Category] ), Product[ProductCategory] )
)
```

The budget's categories filter the Product table, and the filter reaches Sales through the normal relationship from Product. This assumes the same Budget table as above.

## Things to watch
- Values must match in spelling, case and data type. A trailing space makes "Online" and "Online " different.
- The column count must match the expression. A mismatch is an error.
- The filter arrives on the target column and then moves on through the relationships from there. Test the result with a simple visual before you trust it.
- The model still has no relationship. Anyone who changes the report later will not see one in the model view.
- A proper relationship is clearer when you can add one. Use TREATAS when you cannot.

## In business terms
Budget and forecast tables kept at a different grain, mapping tables for account groupings, and any join where the keys are not modeled. Finance teams use it to compare budget with actuals when the budget file came from a different system.
