DAX, short for Data Analysis Expressions, is the formula language Power BI uses to write measures, calculated columns and calculated tables. It looks like Excel, but a DAX measure has no fixed answer: it is recalculated for every cell of every visual, inside whatever filters apply to that cell. Learn how those filters work and how CALCULATE changes them, and most of DAX follows.
Our Power BI tutorial lists the first dozen functions and builds four basic measures. This lesson is the next layer: why a measure returns what it returns, with every result below checked against the sample data.
Where you write DAX in Power BI Desktop
There are five entry points, and each makes something different.
| Where | Click path | What it creates |
|---|---|---|
| New measure | Home ribbon or Modeling ribbon, New measure | A measure, calculated when a visual asks for it |
| New column | Modeling ribbon, New column, or Table tools, New column | A calculated column, computed row by row at refresh and stored |
| New table | Modeling ribbon, New table | A calculated table, such as a date table |
| Quick measure | Home ribbon, Quick measure | A measure written for you from a menu of common patterns; read the DAX it produces |
| DAX query view | The fourth icon on the left rail, below Model view | A query window to test measures and see results as a table, without building a visual |
DAX query view is the one most beginners never open, and it is the fastest way to debug. There is a section on it near the end.
The data used throughout
A Bengaluru specialty coffee brand sells beans, cold brew and brewing equipment through its own website and through Amazon. orders has one row per order line:
| order_id | order_date | city | category | channel | qty | unit_price |
|---|---|---|---|---|---|---|
| BC-201 | 2026-04-12 | Bengaluru | Beans | Website | 2 | 650 |
| BC-202 | 2026-05-03 | Mumbai | Beans | Amazon | 1 | 650 |
| BC-203 | 2026-05-18 | Bengaluru | Cold brew | Website | 6 | 120 |
| BC-204 | 2026-06-07 | Delhi | Equipment | Website | 1 | 2400 |
| BC-205 | 2026-06-22 | Mumbai | Cold brew | Amazon | 12 | 110 |
| BC-206 | 2026-07-05 | Bengaluru | Beans | Amazon | 3 | 600 |
| BC-207 | 2026-07-19 | Delhi | Beans | Website | 2 | 650 |
| BC-208 | 2026-08-02 | Bengaluru | Equipment | Amazon | 1 | 2200 |
A Date table, created with Date = CALENDAR(DATE(2026,4,1), DATE(2027,3,31)) and marked as the date table, is related one-to-many to orders[order_date]. In a real model, city, category and channel would sit in their own lookup tables; they are kept in orders here so every example fits on one screen.
The first measure, which every later one builds on:
| Measure | DAX |
|---|---|
| Revenue | SUMX(orders, orders[qty] * orders[unit_price]) |
Filter context: the idea behind every result
Put Revenue in a table visual with city on the rows, and you get three different answers from one formula:
| city | Revenue |
|---|---|
| Bengaluru | 6,020 |
| Delhi | 3,700 |
| Mumbai | 1,970 |
| Total | 11,690 |
Nothing in the measure mentions a city. For the Bengaluru row, Power BI filters orders down to the four Bengaluru rows, then evaluates the measure over what is left. That set of filters is the filter context. It comes from the rows and columns of the visual, from slicers, from the filter pane, and from clicks on other visuals. The Total row is not a sum of the rows above it: it is the same measure evaluated with no city filter, which happens to give the same number here and often does not, as the iterator section shows.
Once you think of every number on a page as “this measure, under these filters”, most DAX surprises stop being surprises.
CALCULATE: changing the filters
CALCULATE evaluates an expression after changing the filter context. Its arguments after the first are filters that add to, replace or remove the ones already there. The variations below behave very differently from each other:
| Measure | DAX | What it does to the city filter |
|---|---|---|
| Bengaluru Revenue | CALCULATE([Revenue], orders[city] = “Bengaluru”) | Replaces it with Bengaluru |
| Bengaluru Only | CALCULATE([Revenue], KEEPFILTERS(orders[city] = “Bengaluru”)) | Keeps it and adds Bengaluru on top |
| City Share | DIVIDE([Revenue], CALCULATE([Revenue], ALL(orders[city]))) | Removes it in the denominator only |
| Share of All Orders | DIVIDE([Revenue], CALCULATE([Revenue], ALL(orders))) | Removes every filter on orders in the denominator |
Here is what the first three return in the same city table:
| city | Revenue | Bengaluru Revenue | Bengaluru Only | City Share |
|---|---|---|---|---|
| Bengaluru | 6,020 | 6,020 | 6,020 | 51.5% |
| Delhi | 3,700 | 6,020 | blank | 31.7% |
| Mumbai | 1,970 | 6,020 | blank | 16.9% |
| Total | 11,690 | 6,020 | 6,020 | 100.0% |
Bengaluru Revenue shows 6,020 on the Delhi row because the plain filter argument overwrote the row’s city filter. That is the right behaviour for a fixed benchmark and the wrong one for most other things. KEEPFILTERS intersects instead, so Delhi and Bengaluru together match nothing, and the result is blank.
The difference between ALL(orders[city]) and ALL(orders) shows up once a slicer is involved. Add a channel slicer set to Website:
| city | Revenue | City Share | Share of All Orders |
|---|---|---|---|
| Bengaluru | 2,020 | 35.3% | 17.3% |
| Delhi | 3,700 | 64.7% | 31.7% |
| Total | 5,720 | 100.0% | 48.9% |
City Share removed only the city filter, so its denominator is the 5,720 of Website revenue the slicer allows. Share of All Orders removed the channel filter too, so its denominator is all 11,690. Neither is wrong; they answer different questions. Name your measures so the reader can tell which one they are looking at. REMOVEFILTERS does the same job as ALL inside CALCULATE and reads more clearly, so newer code tends to use it.
Row context and iterators
A calculated column is evaluated once for each row, and inside it you can refer to that row’s values directly. That is row context. A measure has no current row, which is why writing orders[qty] alone inside a measure gives an error asking which row you mean.
Iterators create a row context inside a measure. SUMX, AVERAGEX, MINX, MAXX, COUNTX and RANKX each take a table, evaluate an expression for every row of it, then aggregate. Revenue uses SUMX because the multiplication has to happen per row before the adding.
The common shortcut, multiplying a sum by an average, looks reasonable and is wrong:
| Measure | DAX |
|---|---|
| Wrong Revenue | SUM(orders[qty]) * AVERAGE(orders[unit_price]) |
| category | Revenue | Wrong Revenue |
|---|---|---|
| Beans | 5,050 | 5,100 |
| Cold brew | 2,040 | 2,070 |
| Equipment | 4,600 | 4,600 |
| Total | 11,690 | 25,830 |
On a single category the error is small enough to pass a glance. On the total it more than doubles the answer, because 28 units are multiplied by an average price pulled up by two pieces of equipment. This is the error that gets past review, since every row looks plausible.
Variables make long measures readable
VAR stores an intermediate result, and RETURN gives the final one. Each variable is calculated once, in the filter context where it is defined, which also makes a measure faster when the same expression would otherwise appear twice.
| Line | DAX |
|---|---|
| 1 | Revenue MoM = |
| 2 | VAR CurrentRev = [Revenue] |
| 3 | VAR PrevRev = CALCULATE([Revenue], DATEADD(‘Date'[Date], -1, MONTH)) |
| 4 | RETURN DIVIDE(CurrentRev – PrevRev, PrevRev) |
Type it in the formula bar with Shift+Enter between lines.
Time intelligence for an April to March year
Indian companies report on the financial year, April to March, and Power BI’s year-to-date functions default to a calendar year ending 31 December. TOTALYTD takes an optional year-end date as its last argument.
| Measure | DAX |
|---|---|
| Revenue FYTD | TOTALYTD([Revenue], ‘Date'[Date], “3/31”) |
| Revenue Prev Month | CALCULATE([Revenue], DATEADD(‘Date'[Date], -1, MONTH)) |
| Revenue MoM | The VAR measure in the previous section |
With ‘Date'[Month] on the rows:
| Month | Revenue | Revenue FYTD | Revenue Prev Month | Revenue MoM |
|---|---|---|---|---|
| Apr 2026 | 1,300 | 1,300 | blank | blank |
| May 2026 | 1,370 | 2,670 | 1,300 | 5.4% |
| Jun 2026 | 3,720 | 6,390 | 1,370 | 171.5% |
| Jul 2026 | 3,100 | 9,490 | 3,720 | -16.7% |
| Aug 2026 | 2,200 | 11,690 | 3,100 | -29.0% |
On these months a calendar-year YTD would give the same numbers, because April to August sits inside 2026. The difference shows in January: a calendar YTD restarts at zero, while Revenue FYTD keeps adding until March. A matching Fiscal Year column in the date table, “FY” & IF(MONTH(‘Date'[Date]) >= 4, YEAR(‘Date'[Date]) + 1, YEAR(‘Date'[Date])), lets you put FY2027 on an axis.
All time intelligence functions depend on a proper date table with one row per day and no gaps. If they return blank, check that first.
Ranking and banding
| Object | DAX |
|---|---|
| City Rank (measure) | RANKX(ALL(orders[city]), [Revenue]) |
| Line Value (column) | orders[qty] * orders[unit_price] |
| Order Band (column) | SWITCH(TRUE(), orders[Line Value] >= 2000, “Large”, orders[Line Value] >= 1000, “Medium”, “Small”) |
City Rank returns 1 for Bengaluru, 2 for Delhi and 3 for Mumbai. Without ALL, each row would rank its city against only itself, and every city would come out first, which is the most common RANKX bug.
SWITCH(TRUE(), …) checks conditions in order and returns the first that is true, which replaces a tower of nested IFs. On the sample, it bands the eight orders like this:
| order_id | Line Value | Order Band |
|---|---|---|
| BC-201 | 1,300 | Medium |
| BC-202 | 650 | Small |
| BC-203 | 720 | Small |
| BC-204 | 2,400 | Large |
| BC-205 | 1,320 | Medium |
| BC-206 | 1,800 | Medium |
| BC-207 | 1,300 | Medium |
| BC-208 | 2,200 | Large |
Banding is a column, not a measure, because you want to put it on an axis or in a slicer, and only columns can go there.
Test measures in DAX query view
Open DAX query view from the left rail and type a query. EVALUATE returns a table, and SUMMARIZECOLUMNS builds one grouped by the columns you name, with the measures you list.
| Line | DAX query |
|---|---|
| 1 | EVALUATE |
| 2 | SUMMARIZECOLUMNS(orders[city], “Revenue”, [Revenue], “Share”, [City Share], “Rank”, [City Rank]) |
Click Run and the grid below shows the city table from earlier, with no visual involved. When a measure looks wrong on a report page, reproduce it here with exactly the filters you suspect, one at a time. Right-clicking a measure in the Data pane also offers Quick queries, which writes the EVALUATE statement for you.
Mistakes that produce wrong numbers
Sum times average. Shown above. Anything that multiplies per row needs an iterator.
A FILTER on the whole table inside CALCULATE. CALCULATE([Revenue], FILTER(orders, orders[city] = “Bengaluru”)) works, but filtering an entire fact table row by row is slow on millions of rows. A plain column filter, as in Bengaluru Revenue, does the same job faster.
Forgetting ALL in RANKX and share measures. The symptom is every row ranking 1, or every share showing 100%.
Calculated columns for things that should respond to slicers. A column is fixed at refresh. If a number should change when a reader clicks a slicer, it has to be a measure.
Ignoring blanks. DIVIDE returns blank when the denominator is zero or blank, and visuals hide blank rows. That is usually helpful, until a city with no sales vanishes from a table the reader expected to see it in.
Frequently asked questions
What is DAX in Power BI?
DAX, or Data Analysis Expressions, is the formula language Power BI uses for measures, calculated columns and calculated tables. It looks like Excel formulas, but every DAX measure is evaluated inside the filters a visual applies, so one formula returns a different answer in each cell. The same language is used in Analysis Services and Power Pivot in Excel.
Is DAX hard to learn?
The syntax takes a few days. The hard part is filter context, how a measure’s result depends on the filters around it and how CALCULATE changes them, which usually takes several weeks of building real reports to feel natural. Practise on a dataset whose totals you can check by hand.
What is the difference between DAX and Power Query M?
M is the language behind Power Query, which loads and cleans data before it reaches the model. DAX works after that, on the loaded model, to calculate measures and columns for reports. Use M to shape data once at refresh and DAX for calculations that must respond to a reader’s filters.
What does CALCULATE do in DAX?
CALCULATE evaluates an expression after changing the filter context. Its filter arguments can replace existing filters, add to them with KEEPFILTERS, or remove them with ALL or REMOVEFILTERS. Almost every measure beyond a simple sum uses it.
How do I calculate a financial year to date in DAX?
Use TOTALYTD with a year-end date as the last argument, for example TOTALYTD([Revenue], ‘Date'[Date], “3/31”) for an April to March year. It needs a date table marked as the date table, related to your fact table. DATESYTD takes the same year-end argument when you need it inside CALCULATE.
Should I use a measure or a calculated column?
Use a measure for anything aggregated in a visual, such as a total, an average or a percentage, because it responds to filters and stores nothing. Use a calculated column only for a per-row value you need to slice or group by, such as an order band. When unsure, write a measure.
Practise until filter context feels obvious
DAX rewards repetition on real data. Our Power BI interview questions include the CALCULATE, context transition and ALL questions interviewers ask, and the Microsoft exam tests the same ground, as our PL-300 guide explains. Much of a measure’s logic mirrors SQL aggregation, so a grip on SQL joins helps more than people expect.
SkilloVilla’s Data Analytics with Python track includes a Data Visualization in Power BI module on visualisation and dashboarding, alongside Excel, SQL and Python, with live classes, mentorship from working analysts and placement support.