DAX (Data Analysis Expressions) is the formula language behind Power BI, Power Pivot, and SSAS Tabular. It looks like Excel, but evaluates against an entire filter context instead of single cells. That difference is everything.
What is DAX?
DAX has 250+ functions. You'll use about 30 of them daily. The mental model:
- Every visual on the canvas creates a filter context — the slicers, axis values, and column filters in play.
- A measure is evaluated once per cell in that filter context.
- To change the filter context, you use
CALCULATE.
Measure vs calculated column
| Aspect | Calculated column | Measure |
|---|---|---|
| When evaluated | at refresh time | at query time |
| Stored in | the model (RAM) | computed live |
| Filter context | row-level | whole filter context |
| Use for | static row attributes | aggregations, KPIs |
-- Measure (preferred)Total Sales = SUM(Sales[Amount])Avg Order Value = DIVIDE(SUM(Sales[Amount]), COUNTROWS(Sales))-- Calculated column (only when needed)Sales[Margin Bucket] =SWITCH(TRUE(),Sales[Margin] >= 0.30, "High",Sales[Margin] >= 0.15, "Mid","Low")
CALCULATE — the workhorse
CALCULATE evaluates an expression in a modified filter context. Almost every non-trivial measure uses it.
-- Sales for a fixed regionSales North =CALCULATE([Total Sales],Region[Name] = "North")-- Sales ignoring the region filter (useful for "% of total")Sales All Regions =CALCULATE([Total Sales],REMOVEFILTERS(Region))-- Share of totalRegion Share % =DIVIDE([Total Sales], [Sales All Regions])
Time intelligence
-- Year-to-dateSales YTD = TOTALYTD([Total Sales], 'Date'[Date])-- Same period last yearSales LY =CALCULATE([Total Sales], SAMEPERIODLASTYEAR('Date'[Date]))-- Year-over-year %YoY % =DIVIDE([Total Sales] - [Sales LY], [Sales LY])-- Last 7 days rollingSales 7D =CALCULATE([Total Sales],DATESINPERIOD('Date'[Date], MAX('Date'[Date]), -7, DAY))
Iterators (SUMX / AVERAGEX)
X-functions evaluate row-by-row inside the table you give them.
-- Revenue = quantity * price (per row), then summedRevenue =SUMX(Sales, Sales[Quantity] * Sales[Price])-- Average order value, per order — not weighted by line itemsAOV =AVERAGEX(VALUES(Sales[OrderID]), CALCULATE(SUM(Sales[Amount])))
Variables (VAR / RETURN)
Use VAR liberally — it makes complex measures readable and avoids re-computing the same thing twice.
Profit Margin =VAR Revenue = [Total Sales]VAR Cost = [Total Cost]VAR Profit = Revenue - CostRETURNDIVIDE(Profit, Revenue)
Key takeaways
- 01DAX evaluates inside a filter context — not against single cells like Excel.
- 02Default to measures; use calculated columns only when you need a row attribute.
- 03CALCULATE modifies filter context — almost every advanced measure uses it.
- 04Time intelligence needs a marked Date table — TOTALYTD, SAMEPERIODLASTYEAR are the workhorses.
- 05Iterators (SUMX / AVERAGEX) compute row-by-row inside a table.
- 06Always use VAR / RETURN for readable, performant measures.
