DAX Basics Every Power BI Beginner Needs to Know

Ian Klosowicz

DAX -- Data Analysis Expressions -- is the formula language used in Power BI, Power Pivot, and Analysis Services. If you've used Excel formulas before, DAX will feel familiar in some ways and different in others.

The biggest difference is context. Excel formulas operate on cells. DAX formulas operate on columns, tables, and -- most importantly -- the filter context applied by your report. Understanding that difference is most of what learning DAX is about.

Table of Contents

Measures versus calculated columns

DAX has two main building blocks: measures and calculated columns.

Measures are calculations that run in real time, responding to whatever filters are currently active in your report. When you put a measure on a visual, it recalculates for every cell, every combination of filters. A sales total measure shows total sales for all products when no filter is applied, and shows sales for just the selected product when a product filter is applied. Measures exist in the model but don't add columns to any table.

Calculated columns are computed once when the data loads, row by row. They add a new column to an existing table. A calculated column for full name (first name + last name) computes that concatenation once for every row, then stores it. The value doesn't change based on report filters.

The practical rule: if you need a dynamic calculation that responds to user interaction, use a measure. If you need a fixed value per row -- for grouping, filtering, or as input to another calculation -- use a calculated column.

Filter context

Filter context is the set of filters active at the time a DAX expression is evaluated. It comes from several sources:

  • Slicers on the report page
  • Filters in the filter pane
  • The row or column context in a matrix or table visual
  • Cross-filter effects from other visuals
  • Filters applied explicitly inside DAX with CALCULATE

When Power BI evaluates a measure in a matrix that shows sales by product, it evaluates the measure once for each product -- each time with a filter context that includes only that product. This is what makes DAX powerful and, for beginners, confusing. The same measure can return different values in different cells, because the filter context is different in each one.

Basic aggregations

The most common DAX functions are simple aggregations:

  • SUM(column) -- adds up all values in the column, within the current filter context
  • AVERAGE(column) -- averages the values
  • COUNT(column) -- counts non-blank values
  • COUNTROWS(table) -- counts the number of rows in a table
  • DISTINCTCOUNT(column) -- counts unique values
  • MIN(column) / MAX(column) -- returns the minimum or maximum value

These look similar to Excel functions, but they always aggregate the entire column (filtered by context), not just a range of cells. There's no range reference in DAX -- you reference whole columns.

CALCULATE: the most important function

CALCULATE is the function that changes filter context. Most non-trivial DAX involves CALCULATE in some form.

The basic structure is: CALCULATE(expression, filter1, filter2, ...)

The expression is what you want to calculate -- usually a measure or an aggregation. The filters are modifications to the current filter context.

A simple example: total sales for the East region, regardless of what region filter is active on the report:

East Sales = CALCULATE(SUM(Sales[Amount]), Sales[Region] = "East")

CALCULATE does two things here: it evaluates SUM(Sales[Amount]) in a modified filter context where Region is forced to "East". Any other active filters (date range, product category) still apply -- CALCULATE adds or overrides specific filter conditions, it doesn't replace the entire context.

Functions that modify what CALCULATE does with existing filters:

  • ALL(table or column) -- removes filters on the specified table or column
  • ALLEXCEPT(table, column) -- removes all filters except the ones you specify
  • KEEPFILTERS(filter) -- adds a filter without overriding existing ones

Time intelligence

Time intelligence functions calculate across time periods: year-to-date, prior year, rolling averages. They require a properly configured date table.

Common time intelligence functions:

  • TOTALYTD(expression, dates) -- year-to-date total
  • SAMEPERIODLASTYEAR(dates) -- returns a date range equivalent to the current period, one year back
  • DATEADD(dates, number, interval) -- shifts a date range by a specified amount
  • DATESYTD(dates) -- returns the dates from the start of the year to the end of the current period

To use these correctly, you need a date table marked as a Date Table in Power BI. Without it, time intelligence functions either error out or return incorrect results.

Common mistakes

The mistakes beginners make most often in DAX:

  • Using a calculated column when a measure is needed. If you want a total that responds to filters, you need a measure, not a column.
  • Forgetting that CALCULATE changes filter context. It's the most common source of unexpected results. When a measure doesn't return what you expect, check whether CALCULATE is involved and what it's doing to the context.
  • Missing or incorrectly configured date table. Time intelligence functions silently return wrong results when the date table isn't set up correctly.
  • Circular references. DAX will tell you when you've created a circular dependency, but it's worth understanding why they happen -- usually from a calculated column that references a column that references it back.

FAQ

Is DAX like Excel formulas?
In syntax, somewhat. Both use parentheses, both use IF statements, both have a lot of the same mathematical functions. The main difference is that DAX works on columns and tables in a model, not on individual cells or ranges. The concept of filter context has no equivalent in standard Excel formulas.

How long does it take to learn DAX?
Basic DAX -- aggregations, simple CALCULATE, a few time intelligence functions -- takes a few weeks of regular practice. Enough to handle most standard reporting requirements. Advanced DAX (complex CALCULATE modifications, iterating functions like SUMX, RANKX) takes months of use on real problems.

Should I use measures or calculated columns for most things?
Measures for most things. Calculated columns make the model larger and are only necessary when you need to filter or group by a computed value, or when you're using the computed value as input to a relationship. If you're aggregating or computing a summary, it's almost always a measure.

What resources are best for learning DAX?
SQLBI.com has the most rigorous technical content -- Marco Russo and Alberto Ferrari wrote the book on DAX (literally). The Microsoft documentation is comprehensive but dry. Practice on real data with real questions is how the concepts actually stick.