DAX Formulas in Power BI: A Practical Guide

DAX is what drives calculations inside the Power BI model. We cover the core functions, time intelligence, common mistakes and ready-made formulas for business reports.
When a driver who has spent years with an automatic gearbox gets behind the wheel of a manual, the familiar moves suddenly stop working. Excel and Power BI feel much the same: SUM, IF and FILTER look familiar, but the calculation logic is different. DAX formulas in Power BI operate on row and filter context — and that is exactly what requires a change of habits.
In this guide we look at what DAX is, how it differs from Power Query, which functions you need first and where the typical mistakes come from. The material suits both DAX for beginners and experienced analysts.
What DAX is and why you need it
DAX is Microsoft’s formula and expression language for Power BI, Analysis Services and Power Pivot in Excel. DAX is used to create measures, calculated columns and tables. The result of a calculation depends on the structure of the model and on the context in which the formula is evaluated.
Excel formulas usually refer to cells and ranges, whereas DAX formulas work with the tables and columns of the model. A measure based on SUM, for instance, is recalculated according to the filters currently applied in the report.
Why an analyst needs DAX:
- Calculating business metrics: margin, conversion, LTV — figures you cannot get by simply summing a column.
- Time intelligence: year-over-year comparisons, running totals, opening and closing values for a period.
- Dynamic calculations: measures are recalculated according to the filters the user selects and do not store a separate result for every row.
If a company uses Power BI for business, DAX is what provides custom metrics and calculations that change together with the report filters.
DAX vs Power Query: what is the difference
Power Query prepares and transforms the data before it is loaded into the model, while DAX performs calculations inside the model.
| Criterion | Power Query | DAX |
|---|---|---|
| When it works | At the data loading and preparation stage | Inside the data model: calculated columns and tables are evaluated during data refresh, and measures while you work with the report. |
| What it does | Cleans, filters and merges tables from different sources | Performs calculations inside the data model: creates measures, calculated columns and tables. |
| Language | M (Power Query M) | DAX (Data Analysis Expressions). |
| Result | A new table or column in the model | Depends on the type of calculation: a measure changes its result according to the current filters, while calculated columns and tables store the calculated values in the model. |
| Example task | Merge data from a CRM and an Excel file into one table | Calculate the share of repeat customers out of the total number |
Power Query is responsible for preparing the data, and DAX functions for the calculations inside the model. A syntactically correct DAX formula can still return a wrong result because of an error in the logic, the relationships or the context.
Core DAX functions
There is no need to learn all DAX functions at once. It is more important to master the basic ones first and understand how context affects a calculation.
CALCULATE
CALCULATE is one of the key DAX functions: it evaluates an expression in a modified filter context.
Basic syntax:
CALCULATE(<expression>, <filter1>, <filter2>, …)
Example: you need to calculate the sales of the “Electronics” category even if another category is selected in the report through the Product[Category] field:
Electronics Sales = CALCULATE(SUM(Sales[Amount]), Product[Category] = “Electronics”)
CALCULATE replaces the current filter on Product[Category], but the filters by period, region and so on stay in effect. This is one of the basic principles behind more complex DAX formulas.
SUM, SUMX and iterator functions
SUM is the simplest aggregation function; it sums the values of a single column:
Total Amount = SUM(Sales[Amount])
For calculations where the expression has to be evaluated for every row, you use the iterator functions SUMX, AVERAGEX and COUNTX. They evaluate the expression row by row and then aggregate the result.
A classic example is revenue, when price and quantity are stored in different columns:
Revenue = SUMX(Sales, Sales[Quantity] * Sales[Price])
SUM does not fit this example, because the values in each row have to be multiplied first.
Time intelligence — formulas for periods
DAX date functions are used to compare periods — month over month, year over year — or to build a running total.
- SAMEPERIODLASTYEAR returns the set of dates for the corresponding period of the previous year.
- DATESYTD returns the set of dates from the beginning of the year up to the current date in the calculation.
- PREVIOUSMONTH and PREVIOUSQUARTER return the dates of the previous month or quarter.
- DATEADD shifts a set of dates by a given time interval.
These functions are usually used inside CALCULATE, so that the required figure is calculated on the basis of the returned set of dates.
An example formula for a year-over-year sales comparison:
Sales Last Year = CALCULATE(SUM(Sales[Amount]), SAMEPERIODLASTYEAR(Calendar[Date]))
Such formulas in Power BI are used in KPI dashboards to compare figures across periods automatically.
Classic time intelligence requires a separate date table with unique values, no gaps and no blanks, covering full years and marked as a date table in Power BI.
Common mistakes when writing DAX
If you are only learning how to write DAX formulas, it is worth starting with the mistakes that directly affect the result of a calculation. Here are the most common DAX mistakes and how to avoid them.
- Confusing row context with filter context. The first defines the current row, in SUMX among others; the second is the set of data that enters the calculation under the effect of filters, relationships and the formula itself.
- A calculated column instead of a measure. A column is evaluated during refresh and stored in the model, while a measure is evaluated while you work with the report and responds to filters. A dynamic figure usually calls for a measure.
- Division without checking the denominator. If it can be zero or blank, use DIVIDE: Margin % = DIVIDE([Profit], [Revenue]). By default the function returns BLANK; a different value can be set with the third argument.
- Suboptimal filters in CALCULATE. For simple conditions it is better to filter directly on the column and to use FILTER for more complex logic.
- Unclear measure names. "Measure1" makes the model harder to maintain, while "Margin % current month" shows the purpose of the calculation right away.
Examples of DAX formulas for business reports
Here are several DAX formulas for typical business reports:
Share of repeat customers:
% Repeat Customers = VAR RepeatCustomers = FILTER( VALUES(Sales[ClientID]), CALCULATE(DISTINCTCOUNT(Sales[OrderNumber])) > 1 ) RETURN DIVIDE( COUNTROWS(RepeatCustomers), DISTINCTCOUNT(Sales[ClientID]) )
A repeat customer here is one with more than one unique order in the current report context.
Running total of sales since the beginning of the year:
Sales YTD = TOTALYTD(SUM(Sales[Amount]), Calendar[Date])
Change versus the previous month (in %):
Sales Previous Month = CALCULATE( [Total Amount], PREVIOUSMONTH(Calendar[Date]) )
MoM Change % = DIVIDE( [Total Amount] – [Sales Previous Month], [Sales Previous Month] )
TOP-N products by revenue (for ranking visuals):
Product Rank = RANKX(ALL(Product[Name]), [Revenue], , DESC)
To get exactly the TOP-N products, apply the corresponding filter to the visual after the ranking is calculated — Product Rank <= 10, for example.
Active customers over the last 90 days:
Active Customers 90d = CALCULATE( DISTINCTCOUNT(Sales[ClientID]), DATESINPERIOD(Calendar[Date], MAX(Calendar[Date]), -90, DAY) )
How IWIS builds complex DAX models for clients
IWIS business intelligence projects include solutions for Planeta Kino, Helen Marlen, BAT, Swiss Krono and other companies. In complex Power BI models the business logic often goes far beyond basic SUM and CALCULATE.
A typical sequence of the team’s work on a DAX model:
- Business logic audit. The team clarifies how the company calculates each metric and agrees on a single set of rules.
- Data model design. The table structure, the date table and the relationships between them determine how complex the DAX formulas will be.
- Writing and optimising measures. Performance is tested on data close to the production set in volume and structure.
- Documenting the logic. For complex metrics, the data sources and calculation rules are recorded.
Free consultation from IWIS
If DAX formulas return the wrong result, the dashboard is slow or the figures do not add up, what needs checking is the model, the relationships, the filters, the business logic and the formulas themselves.
During a free consultation the IWIS team will:
- analyse your data structure and DAX model;
- find the reasons behind discrepancies in the calculations;
- advise which metrics are worth reworking or optimising;
- suggest a format for implementing business intelligence based on Power BI that fits your processes.
Let's sort out your DAX model
Request a free consultation — we will go through your data model and calculations together.
Get in touchFrequently Asked Questions
What is DAX in Power BI?
DAX (Data Analysis Expressions) is the formula language used for calculations in Power BI. DAX works with the tables, columns and relationships of the data model, and the result of a measure changes depending on the filters currently applied in the report.
What is DAX used for?
DAX lets you build your own business metrics: calculate margins, compare figures across periods or build a running total. Power BI works without custom DAX formulas too, but DAX in Power BI is needed for calculations that are not present in the source data and that have to change depending on the report filters.
How does a measure differ from a calculated column?
A calculated column is evaluated when the data is refreshed, and its values are stored in the model. A measure is evaluated while you work with the report and responds to the current filters, such as the selected region or period. Dynamic indicators usually call for measures, while calculated columns are needed for row-level calculations.
Which DAX functions should an analyst know?
A confident command of the basic set is enough: CALCULATE (changing the filter context), SUM and SUMX (aggregation), DIVIDE (safe division) and the time intelligence functions — SAMEPERIODLASTYEAR, DATESYTD, TOTALYTD.
How does the CALCULATE function work in DAX?
CALCULATE evaluates an expression after the filter conditions have been changed. It lets you calculate the sales of a specific category, for example, by replacing the current filter with the product category while keeping the other report filters in place. That is why understanding CALCULATE is required to build many of the more complex DAX formulas.
Which DAX formulas should you start with?
DAX for beginners is best started with the basic aggregation functions SUM, AVERAGE and COUNT, then DIVIDE and CALCULATE, and after that the time intelligence functions. Classic period-based calculations also require a separate date table that is created and configured correctly.
Interesting materials for you