EVALUATE DAX Statement
EVALUATE is a DAX statement that is needed to execute a query. EVALUATE followed by any table expression returns the result of the table expression. Moreover, one or more EVALUATE statements can be preceded by special definitions like local tables, columns, measures, and variables that have the scope of the entire batch of EVALUATE statements executed together.
-- Definition section [DEFINE { MEASURE <tableName>[<name>] = <expression> } { COLUMN <tableName>[<name>] = <expression> } { TABLE <tableName> = <expression> } { VAR <name> = <expression>}] -- Query expression EVALUATE <table> -- Result modifiers [ORDER BY {<expression> [{ASC | DESC}]}[, …] [START AT {<value>|<parameter>} [, …]]]
An EVALUATE statement is divided into three parts:
- Definition section: introduced by the DEFINE keyword, it includes the definition of local entities like tables, columns, variables, and measures. There can be a single definition section for one or more queries.
- Query expression: introduced by the EVALUATE keyword, it contains the table expression to evaluate and return as the result. There might be multiple query expressions, each introduced by EVALUATE and each with its own set of result modifiers.
- Result modifiers: an optional additional section to EVALUATE, which is introduced by the keyword ORDER BY. It includes the sort order of the result and the optional definition of which rows to return, by providing a starting point with START AT.
The first and third parts of the statement are optional. Thus, one can just use EVALUATE followed by any table expression to produce a query.
Here is an example of a query:
DEFINE VAR MinimumAmount = 2000000 VAR MaximumAmount = 8000000 EVALUATE FILTER ( ADDCOLUMNS ( SUMMARIZE ( Sales, 'Product'[Category] ), "CategoryAmount", [Sales Amount] ), AND ( [CategoryAmount] >= MinimumAmount, [CategoryAmount] <= MaximumAmount ) ) ORDER BY [CategoryAmount]
Category | CategoryAmount |
---|---|
TV and Video | 4,392,768.29 |
Computers | 6,741,548.73 |
Cameras and camcorders | 7,192,581.95 |
Last update: Aug 7, 2022 » Contribute » Show contributors
Contributors: Alberto Ferrari, Marco Russo
Microsoft documentation: https://docs.microsoft.com/en-us/dax/evaluate-statement-dax