Fabric deployment pipelines: test changes before they go live
How deployment pipelines in Microsoft Fabric move your reports and models from development to test to production, and the settings that trip up beginners.
If you learn one DAX function properly, make it CALCULATE. It sits behind year-on-year comparisons, percentage of total, "sales for one region only" and most other measures that go beyond a simple sum. It is also the function that most often produces numbers that look wrong to a beginner.
The good news is that CALCULATE does one job. Once you can picture that job, its results stop being surprising. This guide explains it step by step, with diagrams and short examples.
Imagine a table visual with one row per region and a Total Sales measure. The measure is the same formula on every row, yet each row shows a different number. That is because each cell is calculated under its own filters: the North row has the filter "Region = North", the South row has "Region = South", and so on. Slicers, page filters and report filters add to these.
That combined set of filters for one cell is its filter context. A plain measure simply works within whatever filter context it is given:
Total Sales =
SUM ( Sales[Sales Amount] )
CALCULATE is how you change the filter context inside a measure, instead of accepting it as it is.
Microsoft's documentation describes CALCULATE in one line: it evaluates an expression in a modified filter context. The syntax is:
CALCULATE ( <expression>, <filter1>, <filter2>, ... )
The first argument is the calculation, usually an existing measure. Everything after it is a filter. CALCULATE works in three steps:
Here is a measure that always shows North's sales:
North Sales =
CALCULATE ( [Total Sales], 'Customer'[Region] = "North" )
'Customer'[Region] = "North" is a Boolean filter expression: a simple true-or-false test on a column. Put this measure in the region table and something interesting happens. Every row shows North's figure, including the South and East rows.
That is step 2 at work. Each row already has a filter on Region. The new filter is on the same column, so it replaces the row's filter rather than adding to it. The South row is no longer filtered to South; it is filtered to North.
This is often exactly what you want, for example to show a benchmark region next to every other region. When it isn't, you need KEEPFILTERS.
KEEPFILTERS changes that replace behaviour. Microsoft's documentation puts it simply: CALCULATE's filters replace the current context, whereas KEEPFILTERS adds filters to the current context. Both filters must then be true at once.
North Sales (kept) =
CALCULATE ( [Total Sales], KEEPFILTERS ( 'Customer'[Region] = "North" ) )
Now the North row still shows North's sales. The South row is asked for rows that are both South and North, which don't exist, so it returns blank. Visuals hide blank results by default, so this version effectively says "North's sales, but only where North is already in view".
The same table visual with four measures
| Region | Total Sales | North Sales | North Sales (kept) | % of all regions |
|---|---|---|---|---|
| North | 500 | 500 | 500 | 50% |
| South | 300 | 500 | blank | 30% |
| East | 200 | 500 | blank | 20% |
| Total | 1,000 | 500 | 500 | 100% |
The third common need is to compare a figure with a bigger total, such as each region's share of all sales. For that, you remove a filter instead of replacing it.
Sales % of All Regions =
DIVIDE (
[Total Sales],
CALCULATE ( [Total Sales], REMOVEFILTERS ( 'Customer'[Region] ) )
)
The top half of the division is the row's own sales. The bottom half uses CALCULATE with REMOVEFILTERS, which clears filters from the column you name. So for every row, the bottom half is total sales across all regions, and the result is that region's share. Microsoft's CALCULATE page uses the same pattern for a sales channel.
Two things are worth knowing:
DIVIDE is used here instead of / because it returns blank, not an error, if the bottom half is zero or blank.
Boolean filter expressions like 'Customer'[Region] = "North" are the fastest and clearest way to filter, but Microsoft's documentation sets some rules. A Boolean filter expression:
Microsoft's DAX best-practice guidance recommends passing filters as Boolean expressions whenever possible, rather than wrapping a whole table in FILTER, because Import model tables are in-memory column stores optimised to filter columns this way. You still need FILTER when the condition depends on a measure, since a measure can't be used in a Boolean filter argument.
You can pass several filters, separated by commas. Filters on different columns all apply together, so this returns North's sales for one product category:
North Bikes Sales =
CALCULATE (
[Total Sales],
'Customer'[Region] = "North",
'Product'[Category] = "Bikes"
)
There is one more thing CALCULATE does, which you will meet in calculated columns and in iterator functions such as SUMX. In those places DAX works one row at a time (row context), not with filters. Microsoft's documentation explains that CALCULATE transitions row context to filter context: the current row's values become filters. This is called context transition.
You rarely need to write it yourself, because Microsoft notes that when you reference a measure in row context, context transition happens automatically. It is the reason a measure like [Total Sales] inside a calculated column on the Customer table returns each customer's own sales, rather than the grand total.
Customer), so the filter flows to the fact table through the relationship.CALCULATE does one thing: it changes the filters before evaluating a calculation. A filter on an already-filtered column replaces it, KEEPFILTERS keeps both, and REMOVEFILTERS takes a filter away. Picture the filter context of each cell before and after CALCULATE, and benchmarks, shares of total and comparisons become predictable, readable measures.
Free every Friday
Join our free live class every Friday at 6pm UK time: hands-on lessons, live Q&A and career tips from a working Senior Data Analyst.
Keep reading
How deployment pipelines in Microsoft Fabric move your reports and models from development to test to production, and the settings that trip up beginners.
A simple SQL query that sorts every customer into active, at risk, lapsed or never ordered, so you know who to contact before they're gone for good.
What OneLake shortcuts are, which sources they can point to, and when a shortcut beats copying data into Microsoft Fabric for your business.
The Data Brief
New guides on Power BI, Fabric and SQL, plus class and cohort dates first. Free, and you can unsubscribe any time.