Query-scoped definitions
Temporary definitions are a query workspace
A DEFINE block creates named expressions for the duration of a query. Use it to compare a proposed measure with a saved measure without changing model metadata. In a disposable model, DEFINE MEASURE associates a scalar expression with an existing table; a query-scoped measure can shadow an existing measure with the same name for that query only. Use the isolated fixture in labs/dax-queries/README.md. Import QuerySales and QueryCategory, whole-number LineID/Amount, text Category, one-to-many active single-direction relationship from QueryCategory to QuerySales. No other relationships, filters or RLS in this disposable local model. Native execution is pending; outputs below are offline predictions.
Scope and evaluation
Write one DEFINE block before the first EVALUATE. MEASURE definitions are evaluated in the context in which they are used. DEFINE VAR can hold a scalar or table; a scalar variable defined at query scope does not become a per-group measure merely because it is referenced inside a grouping expression. Query-local VAR names are not model columns. Avoid internal query-scoped TABLE and COLUMN definitions; they may fail at runtime. Query-scoped definitions are not saved measures unless an explicit model update is performed.
Example 1 — test a temporary share measure
DEFINE MEASURE 'QuerySales'[Trial Revenue] = SUM('QuerySales'[Amount]) MEASURE 'QuerySales'[Trial Share] = DIVIDE([Trial Revenue], CALCULATE([Trial Revenue], REMOVEFILTERS('QueryCategory')))EVALUATESUMMARIZECOLUMNS('QueryCategory'[Category], "Revenue", [Trial Revenue], "Share", [Trial Share])ORDER BY 'QueryCategory'[Category] ASCExpected rows (Category, Revenue, Share): A 150, 3/7; B 100, 2/7; C 100, 2/7; D 0, 0. E is absent because both named expressions are blank for that group. The denominator removes category filters only, so other filters would remain. Shares total 1 in the unfiltered fixture. Format or round only for display.
Example 2 — contrast a variable with a measure
DEFINE VAR Baseline = SUM('QuerySales'[Amount]) MEASURE 'QuerySales'[Trial Revenue] = SUM('QuerySales'[Amount])EVALUATESUMMARIZECOLUMNS('QueryCategory'[Category], "Revenue", [Trial Revenue], "Baseline", Baseline)ORDER BY 'QueryCategory'[Category] ASCEVALUATE ROW("Baseline", Baseline)Result 1: A 150/350, B 100/350, C 100/350, D 0/350, E blank/350 (Revenue/Baseline). The constant nonblank Baseline keeps E in this grouping. Result 2: one Baseline value of 350. Baseline is deliberately frozen at query scope; Trial Revenue is recalculated by group. Compare actual numeric blanks, not just displayed text.
Debug scope without mutation
If every row returns 350, check whether you evaluated an aggregate before establishing the intended group context. Move the aggregate to a measure or evaluate it inside the intended iterator. To test shadowing, use a disposable model with a saved test measure, run a query-local alternate formula, then run a separate query without DEFINE and confirm the original value remains. Do not press Update model with changes or use a write operation. Existing RLS is not bypassed by a query-local definition.
Practice and references
Define a temporary line-count measure and compare grouped results to the frozen total of six lines. Explain why E disappears if all expressions are blank and why it reappears with a constant.