Free live training · Power BI & SQL every Friday, 6pm UKSave your seat Staff login

Home  /  Insights  /  Power BI

Power BI

CALCULATE in Power BI: how it changes the filters on your numbers

A plain-English guide to the most important DAX function: what filter context is, how CALCULATE replaces or keeps filters, and how to build a percentage of total.

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.

In short

  • Every number in a visual is worked out under a set of filters, called its filter context.
  • CALCULATE evaluates an expression in a modified filter context: you add, replace or remove filters before the sum is done.
  • A filter on a column that is already filtered replaces the existing filter, unless you wrap it in KEEPFILTERS.
  • REMOVEFILTERS clears filters, which is how you build a percentage of total.

First, what filter context is

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.

What CALCULATE does

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:

  1. Start with the filter context of the cell: the visual's row, slicers and page filters.
  2. Apply each filter argument. A filter on a column that is already filtered replaces that filter. Filters on other columns are left alone.
  3. Evaluate the expression under the new set of filters and return the result.
North Saleson the South row
1. StartRegion = South, Year = 2026
2. Apply filterRegion = North replaces South
3. New contextRegion = North, Year = 2026
4. Evaluate[Total Sales] for North in 2026
What CALCULATE does in one cell. The South row arrives with two filters. The new Region filter replaces the old one because it is on the same column, while the Year filter is left alone. Only then is the sum worked out.

Example 1: sales for one region

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.

Example 2: keeping the existing filter with 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

RegionTotal SalesNorth SalesNorth Sales (kept)% of all regions
North50050050050%
South300500blank30%
East200500blank20%
Total1,000500500100%
Sample figures. North Sales replaces each row's region filter, so every row shows North. The KEEPFILTERS version keeps both filters, so South and East return blank. The percentage removes the region filter from the bottom of the division, so every row is compared with all regions.

Example 3: percentage of total with REMOVEFILTERS

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:

  1. REMOVEFILTERS also clears slicer filters on that column. If someone picks two regions in a slicer, the bottom half still uses all regions, so the shares won't add up to 100%. Other filters, such as a year slicer, still apply.
  2. You will often see ALL used the same way in older examples. Microsoft notes that ALL works both as a filter modifier and as a function that returns a table, and recommends using REMOVEFILTERS to remove filters where your tool supports it, because its intent is clearer.

DIVIDE is used here instead of / because it returns blank, not an error, if the bottom half is zero or blank.

The rules for simple filters

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:

  • can reference columns from a single table;
  • can't reference measures;
  • can't use a nested CALCULATE;
  • can't use functions that scan or return a table, unless they are passed to an aggregation function.

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"
)

A note on context transition

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.

A quick checklist when a CALCULATE result looks wrong

  1. What is the filter context of this cell? List the row, column, slicer and page filters.
  2. Does a filter argument use a column that is already filtered? If so, it replaces that filter. Use KEEPFILTERS if you want both to apply.
  3. Are you removing a filter people expect to keep? REMOVEFILTERS ignores slicers on that column too.
  4. Is the filter column in the right table? Filter the dimension table (such as Customer), so the filter flows to the fact table through the relationship.

The bottom line

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.

JC
Jayne Carter

Data Engineer at Intelligence With Data.

Free every Friday

Learn Power BI & SQL live, for free

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.

The Data Brief

Practical data tips, once a week.

New guides on Power BI, Fabric and SQL, plus class and cohort dates first. Free, and you can unsubscribe any time.