Power BI Lesson 6: CALCULATE and Filter Context

📎 This article includes 2 downloadable practice files ↓

⏱ 2 min read

📘 Power BI & DAX Beginner Course · Lesson 6 of 10

In this article
  1. Filter context in action
  2. CALCULATE adds or replaces filters
  3. Removing filters: share of total
  4. KEEPFILTERS
  5. Context transition, briefly
  6. Where beginners go wrong
  7. Practice

Every number in a Power BI visual is calculated under some filters: the row it’s on, slicers, page filters. That set of filters is the filter context. CALCULATE lets a measure change it, and that’s what makes DAX powerful.

Filter context in action

In a table with Region down the side, the North row’s [Total Sales] is computed with Region = North in force. Add a Category slicer set to Computers, and it’s North and Computers. You never wrote a filter; the visual supplied it.

CALCULATE adds or replaces filters

Computers Sales = CALCULATE ( [Total Sales], Products[Category] = "Computers" )
North Sales     = CALCULATE ( [Total Sales], Customers[Region] = "North" )
Big Orders      = CALCULATE ( [Orders], Sales[Qty] >= 5 )

A filter on a column inside CALCULATE replaces any existing filter on that same column. So “Computers Sales” shows Computers even on a row for Peripherals.

Removing filters: share of total

All Regions Sales = CALCULATE ( [Total Sales], REMOVEFILTERS ( Customers[Region] ) )
Region Share %    = DIVIDE ( [Total Sales], [All Regions Sales] )

On the North row, All Regions Sales ignores the region filter, so the share is North ÷ everything. (ALL(Customers[Region]) works the same way inside CALCULATE.)

💡 Keep slicers working in share-of-total measures by removing only the filter you mean (the Region column), not ALL(Customers) or ALL(Sales).

KEEPFILTERS

CALCULATE([Total Sales], KEEPFILTERS(Products[Category] = "Computers")) intersects with the existing filter instead of replacing it: on a Peripherals row it returns blank instead of the Computers total.

Context transition, briefly

Inside an iterator like SUMX or a calculated column, CALCULATE turns the current row into a filter. That’s why measures used inside SUMX over a dimension “know” which row they’re on. You’ll meet this again in advanced DAX.

Where beginners go wrong

Mistake Effect
Using FILTER(Sales, …) for simple conditions Slower; plain column conditions are better
ALL(Sales) in share measures Ignores every slicer
Expecting CALCULATE filters to add to the same column’s filter They replace it; use KEEPFILTERS

More: CALCULATE explained.

Practice

Download the data model and expected results below. Load all four tables into Power BI Desktop and build this lesson’s steps; compare your numbers with the expected-results workbook.

📎 Practice files for this article

  • 📗
    Practice data model (Excel)Four tables: Sales (600 orders, FY 2024-25 and 2025-26), Products, Customers and a Calendar with FY columns.
    ⬇ XLSX · 40 KB
  • 📗
    Expected resultsThe values your measures and visuals should show.
    ⬇ XLSX · 7 KB

Free to use for learning. Files with macros (.bas) are plain text — import them with Alt+F11 → File → Import File, and always test on a copy.

✨ Ask AI about this article

Stuck on a step? Ask a question and the AI answers using this article.

Free · AI can be wrong