Skip to main content
Taught by Tech Leads

Master pipelines, cloud & AI to become an operational Data Engineer.

DataScientist.fr
Image de Beginner's Guide to DAX | Power BI Tutorial
Data Scientist
Big Data
SQL

Beginner's Guide to DAX | Power BI Tutorial

Photo de Hamza GUEREHOUNE

Tech Lead Data, Senior Analytics Engineer

Published on 22 septembre 2025 · 15 min of reading

TL;DR: In this article, we will explore in-depth the DAX (Data Analysis Expressions) language used in Power BI. DAX is a set of functions, operators, and constants that can be combined to create formulas and expressions in Power BI, Analysis Services, and Power Pivot in Excel data models.
This guide, designed as a comprehensive and practical tutorial, targets beginners as well as advanced users who wish to strengthen their skills. With clear explanations, practical examples, and advanced tips, it will guide you step by step to understand and master DAX.

Introduction to DAX in Power BI

The DAX (Data Analysis Expressions) language is at the heart of Power BI, Power Pivot, and Analysis Services. It is a formula language specifically designed for data modeling and creating dynamic calculations. It can be compared to Excel formulas, but with one fundamental difference: whereas Excel generally limits itself to cell-by-cell calculations, DAX works with complete relational models. In other words, it allows for leveraging relationships between multiple tables and performing analyses that automatically adjust to filters applied in your reports.

Why is DAX so important?

In a professional context, databases are rarely simple. You may have millions of rows of sales, customer tables, product tables, and time dimensions. How can you quickly answer questions such as:
  • What is the revenue generated in each region this month?

  • What is the sales growth compared to last year?

  • Which products contribute the most to my overall revenue?

With DAX, you don’t need to manually recreate or filter your data: the formulas directly connect to your model and adapt to the chosen context (by date, product, region, etc.). This flexibility is what makes DAX powerful.

The key benefits of DAX

  1. Automation of complex calculations: instead of creating dozens of columns or manual queries, a single DAX measure can adjust to different filters and provide dynamic results.

  2. Creating business indicators (KPIs): gross margin, conversion rate, annual growth… these are indicators you can calculate and track directly in your dashboards.

  3. Simplified time-based analyses: thanks to so-called Time Intelligence functions, it becomes easy to compare a given period to another (previous month, same month last year, cumulative since the beginning of the year).

  4. Dynamic and interactive models: a DAX formula does not yield a fixed result, it adapts in real-time to the filters applied in your visuals or segments (by product, by region, by period, etc.).

In summary, DAX is the tool that transforms Power BI from a simple visualization tool into a true advanced business intelligence platform.

Understanding the fundamental concepts of DAX

Before writing your first formulas, it is essential to understand how DAX interprets your data.
Three notions constitute the core of the language: row context, filter context, and calculation context.

1. Row context

Row context corresponds to the idea that each row in a table is an independent entity. When you create a calculated column, DAX evaluates the formula row by row, taking into account the specific values of each record.
Simple example:
Profit = Sales[Revenue] - Sales[Cost]
Here, the Profit column will be calculated for each row in the Sales table by subtracting cost from revenue.
Advanced example: You can use an iterative function like SUMX:
Total Profit = SUMX(Sales, Sales[Revenue] - Sales[Cost])
Here, SUMX iterates through each row of the Sales table, calculates profit row by row, and then sums it all up.
Note: row context operates locally on each record.

2. Filter context

Filter context is the set of restrictions applied to the data before DAX executes the calculation. These filters can come from:
  • A Power BI visual (for example, a chart filtered by region or period).

  • A slicer chosen by the user.

  • A relationship between tables that restricts visible values.

  • DAX functions like CALCULATE or FILTER that explicitly modify the active filter.

Basic example: If you display sales in a visual filtered to the year 2024, all your DAX formulas will only consider data from 2024.
Example with CALCULATE:
Sales 2024 = CALCULATE(SUM(Sales[Amount]), YEAR(Calendar[Date]) = 2024)
This measure calculates the total sales but only for the year 2024, regardless of other filters applied in the report.
Note: filter context acts globally and influences which rows are available for the calculation.

3. Calculation context

Calculation context results from the combination of row context and filter context. This allows DAX to execute complex formulas dynamically.
Illustrative example: Imagine a table with sales of several products, and a visual filtered to Q1 - 2024.
  • Filter context selects only the sales from the first quarter of 2024.

  • Row context calculates revenue product by product.

  • Together, they define the calculation context.

Practical example:
Sales Growth = 
VAR PrevYearSales = CALCULATE(SUM(Sales[Amount]), SAMEPERIODLASTYEAR(Calendar[Date]))
RETURN DIVIDE(SUM(Sales[Amount]) - PrevYearSales, PrevYearSales)
In this example:
  • Filter context limits the analysis to the period displayed in the visual.

  • Calculation context adds a comparison with the same period from the previous year.

Note: mastering calculation context is essential for writing reliable measures and avoiding unexpected results.

The main categories of DAX functions

The DAX language is rich with hundreds of functions, but these can be grouped into major categories. Each addresses specific needs: numerical calculations, dynamic filtering, managing relationships between tables, or time-based analyses. Here is a detailed overview, with explanations and practical examples.

Aggregation functions

These functions are used to summarize data. They are the foundation of any analysis.
  • SUM: adds up the values in a column. Example: <code class="inline-code">SUM(Sales[Amount]) calculates the total revenue.
  • SUMX: performs an iterative sum, useful when the total depends on multiple columns. Example: <code class="inline-code">SUMX(Sales, Sales[Quantity] * Sales[UnitPrice]) calculates the total based on quantity × price.
  • AVERAGE: calculates the simple average of a column. Example: <code class="inline-code">AVERAGE(Sales[Amount]).
  • AVERAGEX: similar to SUMX but for averages, allowing for row-by-row iteration. Example: <code class="inline-code">AVERAGEX(Products, Products[Price] * Products[Discount]).
  • COUNT: counts the non-empty values in a column.
  • DISTINCTCOUNT: counts only unique values, very useful for identifying the number of distinct customers, for example.

Filter and context functions

These functions allow modifying or controlling the evaluation context of measures.
  • CALCULATE: the 'king' of DAX functions. It modifies the filter context before performing the calculation. Example: <code class="inline-code">CALCULATE(SUM(Sales[Amount]), Sales[Category] = "Electronics") calculates only electronic sales.
  • FILTER: returns a filtered table. Example: <code class="inline-code">FILTER(Sales, Sales[Amount] > 1000) keeps only sales over 1000.
  • ALL: removes all filters applied to a table or column, often used to compare an individual value to a global total.
  • ALLEXCEPT: removes all filters except those specified. Example: <code class="inline-code">ALLEXCEPT(Sales, Sales[Product]) keeps the product filter but ignores others.
  • VALUES: returns a unique list of values from a column. Useful for creating implicit relationships or counting distinct categories.

Relationship and lookup functions

These functions leverage the relational model of Power BI.
  • RELATED: fetches a value from a related table (one-to-many relationship). Example: <code class="inline-code">RELATED(Customers[Region]) displays the region of the customer linked to each sale.
  • RELATEDTABLE: returns all rows from a related table, often used in measures.
  • LOOKUPVALUE: searches for a value in a column based on criteria. Example: <code class="inline-code">LOOKUPVALUE(Products[Price], Products[ProductID], Sales[ProductID]) retrieves the price of a product corresponding to a sale.

Time-based functions (Time Intelligence)

Essential for chronological analysis, they require a properly configured calendar table.
  • DATEADD: shifts a period in time (days, months, quarters, years). Example: comparing current month sales with the previous month.
  • SAMEPERIODLASTYEAR: returns the same period but from the previous year, perfect for comparing this year vs last year.
  • TOTALYTD / TOTALQTD / TOTALMTD: calculate totals from the beginning of the year, quarter, or month up to the selected date.
  • PARALLELPERIOD: shifts a period while maintaining granularity. Example: comparing January 2024 to January 2023.

Statistical and logical functions

They add conditional logic and more advanced calculations.
  • IF: applies a simple condition. Example: <code class="inline-code">IF(Sales[Amount] > 1000, "Large Sale", "Small Sale").
  • SWITCH: replaces multiple nested IF conditions with a more readable structure. Example: categorizing sales by thresholds.
  • DIVIDE: performs division while automatically handling division by zero. Example: <code class="inline-code">DIVIDE(Sales[Profit], Sales[Revenue]) calculates margin without risk of error.
  • RANKX: assigns a dynamic ranking based on a calculation. Example: <code class="inline-code">RANKX(ALL(Products), SUM(Sales[Amount])) ranks products by their revenue.
In summary, each category of DAX functions helps you address a specific type of need: summarizing your data, controlling calculation context, leveraging relationships between tables, analyzing over time, or applying conditions and rankings. Mastering these families is key to writing robust measures suited to real-world scenarios.

In-depth practical examples

1. Calculating annual growth (YoY Growth)

YoY Growth =
DIVIDE(
    SUM(Sales[Amount]) - CALCULATE(SUM(Sales[Amount]), SAMEPERIODLASTYEAR(Calendar[Date])),
    CALCULATE(SUM(Sales[Amount]), SAMEPERIODLASTYEAR(Calendar[Date]))
)

2. Creating a dynamic product ranking

ProductRank = RANKX(ALL(Products), SUM(Sales[Amount]), , DESC)

3. Determining a product's market share

MarketShare =
DIVIDE(SUM(Sales[Amount]), CALCULATE(SUM(Sales[Amount]), ALL(Sales)))

4. Analyzing sales from loyal customers

FilteredSales =
CALCULATE(
SUM(Sales[Amount]),
FILTER(Customers, Customers[LoyaltyStatus] = "Loyal")
)

5. Cumulative sales since the beginning of the year

YTD Sales = TOTALYTD(SUM(Sales[Amount]), Calendar[Date])

Best practices for writing in DAX

  1. Favor measures over calculated columns.

  2. Use variables (VAR) for improved readability and performance.

  3. Optimize the data model: fewer columns, more well-defined relationships.

  4. Name your measures clearly: for example Total Sales instead of Measure1.

  5. Test your formulas step by step by creating intermediate measures.

Tips and errors to avoid

  • Don't forget to create a calendar table to leverage time functions.

  • Be cautious of implicit filters: a common mistake is to get an empty or incorrect result because CALCULATE modifies the context unintentionally.

  • Avoid creating too many calculated columns that burden the model.

  • Always check your results with smaller datasets before applying your measures to millions of rows.

Advanced use cases

1. Complex Time Intelligence scenarios

Compare this year's sales not only to last year but also to the average of the last three years.

2. Dynamic segmentation

Create categories (small, medium, large client) based on generated revenue, using SWITCH and conditions.

3. Performance analysis

Automatically evaluate whether a region meets its targets through conditional measures and color-coded KPIs.

Conclusion and next steps

DAX is a powerful but demanding language: mastering it relies on a deep understanding of context, using appropriate functions, and adopting best practices.
In summary, you have learned:
  • to use basic functions (SUM, AVERAGE, CALCULATE),

  • to leverage time functions to compare different periods,

  • to write more advanced measures (RANKX, ALL, SWITCH),

  • and to optimize your models for performance.

Next steps:

  • Explore resources like DAX Guide.

  • Practice regularly with your own data.

  • Participate in Power BI communities (forums, LinkedIn, Meetup).

  • Dive into real-world projects by applying DAX to actual business scenarios.

Your learning journey with DAX is a voyage: each formula will bring you closer to a deeper understanding of your data and an enhanced ability to extract strategic insights. Continue to experiment and share your discoveries: that’s how you will become an expert.
Key reminder: DAX is not just a calculation language, it is a gateway between your data and your strategic decisions.

Want to go further?

This topic is part of our Become a Data Analyst course. Browse the full programme, or get it by email.

FAQ

Take a moment to discuss your training project with an advisor.

Share with

Photo de Hamza GUEREHOUNE

Hamza GUEREHOUNE

Tech Lead Data, Senior Analytics Engineer

Expert Power BI et Tech Lead Data fort de plus de 13 ans d'expérience, Hamza a accompagné des grands comptes de la banque, de la pharma et du luxe — L'Oreal, Christian Dior, Orange Bank, Servier — dans leurs projets de transformation data. Il a livré en production des data warehouses cloud, des dashboards financiers et CRM utilisés jusqu'au COMEX, et des pipelines fiables et scalables : migration du data warehouse fraude d'Orange Bank vers Azure, bascule de 2 To de données Servier vers BigQuery, refonte de pipelines SSIS vers Azure Data Factory. Son expertise couvre Power BI, SQL, DAX, Microsoft Fabric, GCP, Airflow et dbt. Formateur certifié, il a déjà guidé plus de 300 apprenants vers la certification PL-300 : sa méthode tient en une idée, apprendre en pratiquant, sur des cas réels, demandés en entreprise et qui transforment la donnée en décisions.

» Learn More

Associated trainings

All our trainings
Image de la formation Become a Data Analyst
Become a Data Analyst
6 months
Intermediate
Guarantee