Domain 2 β€” Module 5 of 7 71%
12 of 26 overall
Domain 2: Model the Data Free ⏱ ~14 min read

CALCULATE & Filter Context

Master the CALCULATE function β€” the most powerful and most tested DAX function on the PL-300 exam. Understand how it modifies filter context and works with ALL, REMOVEFILTERS, and KEEPFILTERS.

The most important DAX function

Simple explanation

Think of CALCULATE as a pair of tinted glasses.

Normally, you see the whole room (all data). Put on blue-tinted glasses and everything looks blue (filtered to one category). CALCULATE puts these glasses on your measure β€” it changes what data the measure β€œsees” before doing its calculation.

CALCULATE(SUM(Sales[Revenue]), Products[Category] = β€œFruit”) says: β€œSum the revenue, BUT only look at fruit sales.” Even if the user hasn’t filtered to Fruit, this measure always shows fruit revenue.

CALCULATE can also REMOVE filters β€” like taking glasses off to see everything again, even when a slicer is active.

CALCULATE basics

Riley at Coastal Fresh (πŸ›’) needs measures that always show specific slices, regardless of user filters:

Fruit Revenue = 
CALCULATE(
    SUM(Sales[Revenue]),
    Products[Category] = "Fruit"
)

This measure ALWAYS shows fruit revenue β€” even if the user selects β€œDairy” on a slicer.

North Region Revenue = 
CALCULATE(
    SUM(Sales[Revenue]),
    Stores[Region] = "North"
)

How it works:

  1. CALCULATE takes the current filter context (whatever slicers/filters are active)
  2. It ADDS the filter Products[Category] = "Fruit"
  3. If there’s already a filter on Category, it REPLACES it
  4. Then it evaluates SUM(Sales[Revenue]) in this modified context

Removing filters with ALL

ALL removes filters from a table or column. Combined with CALCULATE, it lets you ignore specific filters.

Revenue % of Total = 
VAR CurrentRevenue = SUM(Sales[Revenue])
VAR AllRevenue = CALCULATE(SUM(Sales[Revenue]), REMOVEFILTERS())
RETURN
    DIVIDE(CurrentRevenue, AllRevenue)
RegionRevenueRevenue % of Total
North$50K42%
South$30K25%
East$25K21%
West$15K12%
Total$120K100%

REMOVEFILTERS() (with no arguments) removes ALL filters from the entire model, so AllRevenue always returns the grand total of $120K regardless of any active filters. You can also target specific tables or columns: REMOVEFILTERS(Stores) removes only the store filter.

ALL vs REMOVEFILTERS vs ALLEXCEPT

ALL and REMOVEFILTERS remove filters; ALLEXCEPT keeps specific ones; KEEPFILTERS intersects
FunctionWhat It DoesUse When
ALL(table)Removes all filters from the entire tableYou need the grand total, ignoring all filters on that table
ALL(column)Removes filters from a specific column onlyYou want to ignore one filter but keep others
REMOVEFILTERS()Same as ALL but clearer intent β€” removes filtersMicrosoft's recommended replacement for ALL as a filter remover
ALLEXCEPT(table, column)Removes all filters EXCEPT on specified columnsYou want to keep one filter active and remove everything else
KEEPFILTERS()Adds a filter that intersects with existing filters instead of replacingYou want to narrow down, not override the current filter

Practical examples

Nadia at Prism Agency (πŸ“Š) needs campaign metrics that compare against totals:

// Revenue share within each platform (ignores platform filter)
Platform Share = 
DIVIDE(
    SUM(Campaigns[Revenue]),
    CALCULATE(SUM(Campaigns[Revenue]), ALL(Campaigns[Platform]))
)
// Revenue keeping the platform filter but ignoring the campaign filter
Platform Total = 
CALCULATE(
    SUM(Campaigns[Revenue]),
    ALLEXCEPT(Campaigns, Campaigns[Platform])
)
Exam tip: CALCULATE filter replacement

This is the #1 CALCULATE trap on the exam. When CALCULATE has a filter on a column that’s already filtered by a slicer:

CALCULATE replaces the existing filter β€” it doesn’t intersect.

Example: A slicer selects β€œNorth” region. The measure CALCULATE(SUM(Revenue), Region = "South") returns South revenue, NOT zero. CALCULATE replaced the β€œNorth” filter with β€œSouth”.

To intersect (show only if BOTH conditions are true), use KEEPFILTERS: CALCULATE(SUM(Revenue), KEEPFILTERS(Region = "South")) β€” returns zero because North AND South can’t both be true.

CALCULATE with multiple filters

You can stack multiple filter arguments β€” they all apply simultaneously:

North Fruit Revenue = 
CALCULATE(
    SUM(Sales[Revenue]),
    Stores[Region] = "North",
    Products[Category] = "Fruit"
)

This is equivalent to β€œSUM revenue WHERE Region = North AND Category = Fruit”.

Dr. Ethan at Bayview Medical (πŸ₯) uses CALCULATE for compliance metrics:

Emergency After Hours = 
CALCULATE(
    COUNTROWS(Appointments),
    Appointments[Type] = "Emergency",
    'Date'[IsBusinessHours] = FALSE
)

Context transition

When CALCULATE is used inside an iterator function (SUMX, AVERAGEX, etc.) or a calculated column, it triggers context transition β€” converting the current row context into filter context.

This is an advanced concept tested on the exam:

// In a calculated column on the Products table:
Product Revenue = CALCULATE(SUM(Sales[Revenue]))

Without CALCULATE, SUM(Sales[Revenue]) in a calculated column would return the grand total for every row (no filter context). With CALCULATE, context transition converts the row context (current product) into a filter β€” so each product gets its own revenue total.

Knowledge check

Question

What does CALCULATE do?

Click or press Enter to reveal answer

Answer

Evaluates a DAX expression in a modified filter context. It can add, replace, or remove filters before evaluating the expression.

Click to flip back

Question

What's the difference between ALL and ALLEXCEPT?

Click or press Enter to reveal answer

Answer

ALL(table) removes ALL filters from a table. ALLEXCEPT(table, column1, column2) removes all filters EXCEPT on the specified columns.

Click to flip back

Question

What does KEEPFILTERS do inside CALCULATE?

Click or press Enter to reveal answer

Answer

Instead of replacing the existing filter on a column, KEEPFILTERS intersects with it. The result only includes values that satisfy BOTH the existing filter and the KEEPFILTERS condition.

Click to flip back

Knowledge Check

A slicer is set to Region = 'North'. Riley's measure is: CALCULATE(SUM(Sales[Revenue]), Stores[Region] = "South"). What does it return?

Knowledge Check

Nadia needs each campaign's revenue as a percentage of the platform total (e.g., Google Ads total). Which measure is correct?

Next up: Time Intelligence and Calculation Groups β€” year-to-date, year-over-year, and other time-based calculations.