How to Use Power BI DAX

Cody Schneider••9 min read

Dragging and dropping fields in Power BI is a great start, but to unlock truly powerful reports, you need to learn DAX. Data Analysis Expressions, or DAX, is the formula language that lets you move beyond simple summaries to create custom calculations and uncover deeper insights from your data. This article guides you through the fundamentals of what DAX is, why it matters, and how to write your first essential formulas.

GraphedGraphed

Build AI Agents for Marketing

Build virtual employees that run your go to market. Connect your data sources, deploy autonomous agents, and grow your company.

Watch Graphed demo video

What is DAX (and Why You Should Care)

Think of DAX as Excel formulas on steroids, but specifically designed for business intelligence and data modeling in tools like Power BI. It's not a programming language in the traditional sense, you won't be building apps with it. Instead, DAX is a library of functions and operators that you can combine to build formulas (or "expressions") to analyze your data.

Why is this so important? While the basic Power BI interface is great for visualizing what's already in your data tables, DAX lets you create new information from that data. You'll need it to answer more complex business questions like:

  • What was our sales growth percent compared to this same period last year?
  • How many new customers did we acquire this quarter?
  • What is our running total of revenue throughout the year?
  • What percentage of our total sales comes from our top 5 products?

These aren't typically numbers you'll find in a raw data table. They need to be calculated, and DAX is the tool that makes it possible inside your Power BI models.

Calculated Columns vs. Measures: What's the Difference?

Before writing a single formula, you must understand the two primary ways DAX is used: Calculated Columns and Measures. Choosing the right one is fundamental to building an efficient and accurate report.

Calculated Columns

A calculated column is exactly what it sounds like: a new column that you add to one of your existing tables. The DAX formula for a calculated column is evaluated on a row-by-row basis and its values are calculated during data refresh, then stored directly in your data model. This means it uses up memory (RAM) and increases the file size of your report.

Use a Calculated Column when:

  • You want to use the result as a slicer, filter, or in an axis on a chart (e.g., categorizing sales transactions into "High Value" or "Low Value").
  • The calculation is static and depends only on the data within the same row (e.g., [Price] * [Quantity] to get a LineTotal).
  • You need to see the value in the data table itself.

Free PDF · the crash course

AI Agents for Marketing Crash Course

Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.

Measures

A measure is a formula for an aggregation that is calculated on the fly, in real-time, based on the context of your report. When a user interacts with a report - by clicking a slicer or filtering a visual - the measures are recalculated instantly. They don't store any data in your model, so they have a minimal impact on file size.

Use a Measure when:

  • You want to calculate an aggregated value like a sum, average, or count that will appear in the main values area of a visual.
  • The calculation needs to respond dynamically to user selections (e.g., Total Sales should change when you select "Canada" in a country slicer).
  • You are working with rates, percentages, or ratios (e.g., Profit Margin).

Rule of thumb: If you are calculating something that aggregates many rows (like a sum or average), you almost always want a measure. If you are calculating something on a row-by-row basis (like categorizing a single transaction), a calculated column might be appropriate.

The Building Blocks of a DAX Formula

DAX syntax can look intimidating at first, but it breaks down into a few common components. Once you understand them, reading and writing formulas becomes much easier.

1. Functions

Just like in Excel, DAX has a vast library of functions that perform specific actions. Some of the most common ones include:

  • Aggregation Functions: SUM(), AVERAGE(), COUNT(), MIN(), MAX()
  • Logical Functions: IF(), AND(), OR(), SWITCH()
  • Filter and Value Functions: CALCULATE(), FILTER(), ALL(), VALUES()
  • Time Intelligence Functions: SAMEPERIODLASTYEAR(), TOTALYTD() (Year-to-Date), DATESBETWEEN()

The single most important function in all of DAX is CALCULATE(). It allows you to modify the "filter context," which we'll cover shortly.

2. Table and Column References

DAX formulas almost always refer to a table and a column. The syntax is to write the table name followed by the column name in square brackets: TableName[ColumnName].

For example, to access the values in the "Revenue" column from your "Sales" table, you would write:

'Sales'[Revenue]

Note: If your table name has spaces, you need to wrap it in single quotes. It's a best practice to always do this to avoid errors.

3. Operators

These are the symbols that perform mathematical or logical comparisons:

  • Mathematical: +, -, *, /
  • Comparison: =, >, <, >=
  • Logical: && (AND), || (OR), IN (Checks if a value exists in a list)

Understanding Evaluation Context in DAX

"Context" is the most critical concept to grasp in DAX. It determines how your formulas are calculated. There are two primary types of context.

GraphedGraphed

Build AI Agents for Marketing

Build virtual employees that run your go to market. Connect your data sources, deploy autonomous agents, and grow your company.

Watch Graphed demo video

Row Context

Exists when a formula is evaluated for each individual row of a table. It's the "current row." This is mainly used in calculated columns. For instance, if you create a calculated column with the formula 'Sales'[Price] * 'Sales'[Quantity], DAX looks at each row one by one, takes the price and quantity from that specific row, multiplies them, and places the result in the new column for that same row.

Filter Context

Refers to the set of active filters being applied to the data model at any given time. These filters can come from:

  • Rows and columns in a pivot table or matrix visual.
  • Slicers and filters in your report.
  • Other DAX measures in the report.

Measures are almost always evaluated with filter context. When you put a Total Sales measure into a table showing sales by country, the filter context for the "Canada" row is "Country = Canada", and the measure recalculates to show only Canadian sales. This is what makes Power BI interactive.

Writing Your First DAX Formulas: Step-by-Step Examples

Let's get practical. Assume you have a simple data model with a Sales table and a Products table.

Example 1: Create a Simple Measure (Total Sales)

Your Sales table has a Revenue column, and you want to see the total sum across your report. This is a classic use case for a measure.

  1. On the report canvas view, right-click on your Sales table in the Data pane on the right.
  2. Select New Measure.
  3. The formula bar will appear at the top. Type the following formula:

Total Sales = SUM(Sales[Revenue])

Here, you're telling DAX to use the SUM function on the Revenue column of the Sales table. Hit Enter. You'll now see Total Sales in your Sales table with a little calculator icon next to it. You can drag this into a Card visual to see the grand total or into a table/chart to see it sliced by any other field.

Example 2: Create a Calculated Column (Profit Per Unit)

Let's say your Products table has SalePrice and UnitCost columns. You want to create a new column showing the profit for each product, which you can later use to categorize products into profitability tiers.

  1. Navigate to the Data View (the table icon on the left).
  2. Select your Products table from the list on the right.
  3. From the top ribbon, click the New Column button.
  4. In the formula bar, type:

ProfitPerUnit = 'Products'[SalePrice] - 'Products'[UnitCost]

Hit Enter. You will immediately see a new column named ProfitPerUnit appear in your table, with the calculation performed for every single row. Here, the row context is crucial - for each product, the formula subtracts its specific UnitCost from its SalePrice.

Free PDF · the crash course

AI Agents for Marketing Crash Course

Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.

Example 3: Use the CALCULATE Function (Sales for 'USA')

Now for the most powerful function in DAX: CALCULATE. This function lets you change or modify the filter context. Let's say you want a measure that only shows sales for the USA, regardless of what other filters are selected on the page.

  1. Right-click your Sales table and select New Measure.
  2. Enter this formula:

USA Sales = CALCULATE( [Total Sales], 'Sales'[Country] = "USA" )

This formula does two things:

  1. The first part, [Total Sales], is the expression to be evaluated (our measure from Example 1).
  2. The second part, 'Sales'[Country] = "USA", is the filter modification. It tells DAX: "No matter what the current filter context is, add an additional filter where the Country column must be "USA"."

Now, if you put this measure in a card, it will always show the total for the USA, even if you select "Canada" in another slicer on the page.

Best Practices for Writing Clean DAX

  • Format Your Code: Use line breaks and indentation, especially with functions like CALCULATE. This makes complex formulas much easier to read and debug. Online formatters like DAX Formatter can do this for you.
  • Start Simple: Don't try to solve everything in one massive formula. Create simple base measures (like Total Sales) and then reference them in more complex measures.
  • Understand Your Data Model: DAX works best on a well-structured "star schema" data model, where you have fact tables (like Sales) and dimension tables (like Products, Customers, Calendar). Relationships are key!
  • Use Variables (VAR): For more complex formulas, use VAR to store the result of a calculation and then return it with RETURN. This improves readability and can even boost performance.

Final Thoughts

Learning DAX is a journey that transforms your Power BI reports from static visualizations into dynamic, interactive analysis tools. Mastering calculated columns, measures, and the concepts of evaluation context allows you to answer virtually any question your data holds. Start with simple aggregations and build from there - you’ll be a DAX pro in no time.

While mastering Power BI and DAX is a valuable skill, getting answers from your business data doesn't have to be so complex. When building reports, a lot of time is spent just trying to connect data, write formulas, and arrange visuals correctly. We built Graphed to remove this friction. Just connect your data sources - like Google Analytics, Shopify, or Salesforce - in a few clicks, and then ask questions in plain English like, "show me a breakdown of revenue by country last quarter," and the dashboard builds itself instantly. It's like having a data analyst on your team, giving you the power of analysis without the steep learning curve.

Related Articles