Data Analysis Expressions (DAX) is a formula language used in Power BI, Analysis Services, and Power Pivot in Excel.
It allows creating measures and calculated columns or tables, enhancing your data model and allowing you to create complex calculations and aggregations.
Measures and calculated columns and tables are created using Power BI Desktop.
DAX Query
Use DAX Query View to write, edit, and execute DAX queries directly within Power BI Desktop, to step by step test and adjust your calculations before creating measures in the data model.
You can define measures automatically, using "Quick queries" option
Syntax
DAX queries have two main parts:
- An
EVALUATE
statement, which is required. It specifies what and how data is returned in the query. - A
DEFINE
statement, which is optional. It allows you to define DAX formulas, such as a measure, to use in the query.
When returning scalar value, you will need to make additional transformations as query results must be presented as a table.
or
You may also use another syntax, which you see when generating DAX queries automatically, with the "Define all measures in this model" option:
- A
DEFINE
statement - A
RETURN
statement
DAX formula
While DAX queries are used to retrieve data from the data model, DAX formulas create new data elements within that model.
For first steps when creating measures, calculated columns and tables, see the Power BI tutorials.
When moving your DAX queries to a formula, you may simply copy the calculation:
or, if you need additional variables, use VAR
- RETURN
syntax.
The same syntax applies to measures and calculated tables.
Moving Measures
Measures do not "belong" to a table and can reference other measures or data from multiple tables. I like organizing them, to make it easier to find them.
I typically create a separate table, hide the default column, and move the measures using "Measure tools" / "Home table"
Additional resources
See Quick Measures Gallery in Power BI Community, for (mostly) examples of DAX calculations, Power BI dashboard templates and more.
Top comments (0)