Power BI

DAX

Also called: Data Analysis Expressions, DAX formula, DAX measure

DAX (Data Analysis Expressions) is the formula language of Power BI, Analysis Services and Power Pivot, used to write measures, calculated columns and calculated tables in a semantic model.

Three DAX measures: Revenue = SUM(Sales[Amount]), Revenue LY using CALCULATE and SAMEPERIODLASTYEAR, and YoY % using DIVIDE. They drive a KPI card showing Q3 revenue of $2.80M, up 12% on last year's $2.50M, and a column chart of revenue by quarter: Q1 $2.40M, Q2 $2.60M, Q3 $2.80M.

What it looks like

A DAX formula starts with a name, then an equals sign, then an expression. Most report logic lives in measures: formulas that are calculated when a visual needs them.

Revenue = SUM ( Sales[Amount] )

Revenue LY =
    CALCULATE ( [Revenue], SAMEPERIODLASTYEAR ( 'Date'[Date] ) )

YoY % =
    DIVIDE ( [Revenue] - [Revenue LY], [Revenue LY] )

Measures build on each other. Revenue LY reuses Revenue with the dates moved back a year, and YoY % reuses both. In the example, the KPI card shows Revenue of $2.80M and Revenue LY of $2.50M, so YoY % is ($2.80M − $2.50M) ÷ $2.50M = 12%. The column chart reuses the same Revenue measure by quarter: $2.40M, $2.60M and $2.80M.

SAMEPERIODLASTYEAR is a time intelligence function and needs a proper date table: one row per day, with no gaps, related to the fact table.

Filter context: why one measure gives many answers

One Revenue measure in a matrix by region: North America $1.12M, EMEA $0.84M, APAC $0.56M, LATAM $0.28M, total $2.80M. The EMEA cell evaluates SUM(Sales[Amount]) with the filter Region = EMEA to get $0.84M; the total row has no region filter and gets $2.80M

A measure has no single value. Each cell of a visual evaluates it with that cell’s filters applied, which DAX calls the filter context. In the matrix, the EMEA row runs SUM ( Sales[Amount] ) over EMEA rows only and gets $0.84M. The total row has no region filter and gets $2.80M, the sum of the four regions. Slicers, page filters and drillthrough filters all add to the filter context too.

CALCULATE is the function that changes filter context, which is why it appears in almost every non-trivial measure. Revenue LY is Revenue with the date filter swapped for the same period last year.

Where DAX is used

  • Measures: totals, ratios, comparisons and time intelligence for visuals. This is most DAX.
  • Calculated columns: a value per row, worked out at refresh. See measure vs. calculated column.
  • Calculated tables: whole tables built from a formula, such as a date table.
  • Row-level security: role filters such as [Region] = "EMEA".

Best practices

  • Prefer measures to calculated columns for anything that’s aggregated or depends on filters.
  • Use DIVIDE, not ”/”. It returns blank instead of an error when the denominator is zero.
  • Use variables (VAR … RETURN) to name intermediate steps. Formulas get easier to read and often faster.
  • Format and comment measures. Line breaks and a short // comment save the next person an hour.
  • Keep a measures table. Grouping measures in one place makes them easy to find in the field list.

Mocking up before writing DAX

Every number on a mockup becomes a measure, so a signed-off mockup is also a list of the DAX you need to write and the comparisons (vs. last year, vs. target) each one needs. See why to mock up Power BI reports before you build.

See it in a real layout

These free Mockko templates use it. Open one and edit it in your browser.

Related terms

Common questions

Is DAX hard to learn?
The syntax looks like Excel formulas, so simple measures such as SUM or DIVIDE come quickly. The harder part is filter context: understanding which rows a measure sees in each cell, and how CALCULATE changes that.
What's the difference between DAX and Power Query (M)?
Power Query, written in the M language, gets and shapes data before it's loaded into the model. DAX works on the loaded model, calculating measures and columns for the report. Clean data in Power Query, calculate in DAX.
Does Tableau use DAX?
No. Tableau has its own calculation language for calculated fields, with LOD expressions for calculations at a different level of detail than the view. The ideas overlap, but the syntax doesn't.

Mock it up before you build it

Lay out your Power BI or Tableau dashboard in Mockko, get sign-off, then build. Free to start.

Try Mockko free