Power BI Advanced AnalyticsLesson 26 of 53
Lesson 26 of 53

Clearing Filters: ALL, ALLEXCEPT & REMOVEFILTERS

Overview & Learning Objectives

While basic boolean filters in `CALCULATE` work for simple column values (e.g. `City = "Delhi"`), they fail when you need to filter by a measure (e.g. "Customers with Sales > ₹50,000") or compare two columns. For these scenarios, you must use the `FILTER()` function. `FILTER()` is an iterator that scans a table row-by-row and returns a filtered sub-table.

  • Master the syntax of `FILTER(Table, FilterCondition)`.
  • Use `FILTER()` to filter by measure values (e.g. High-Value Customers).
  • Understand the performance cost of scanning large tables with `FILTER()`.

Industry Standard

Standard: Architectural rules at Microsoft and Deloitte warn: Never pass an entire Fact table into `FILTER()`; always pass a slim Dimension table or use `ALL(Column)` to prevent full-table memory scans.

Real-World Example: Spice Delight Cloud Kitchen

Spice Delight wants to calculate revenue generated only by High-Volume Customers (customers who have placed more than 10 lifetime orders).

Customer IDCustomer NameTotal Orders PlacedIncluded in FILTER(..., [Orders] > 10)?
CUST-101Rahul Sharma14 ordersYES (Included in virtual table)
CUST-102Priya Patel6 ordersNO (Excluded by filter condition)
CUST-103Ananya Sen22 ordersYES (Included in virtual table)

Syntax & Core Workflow

High Value Customer Sales = CALCULATE([Total Sales], FILTER(Dim_Customer, [Total Orders] > 10))

Parameters Breakdown

  • Table: The table to iterate over (e.g. `Dim_Customer` or `ALL(Fact_Sales[City])`).
  • FilterCondition: A boolean condition evaluated row-by-row across the table (can reference measures or columns).
  • Iterator Behavior: `FILTER()` steps through each row, establishes row context, and keeps rows where condition is TRUE.

Sample Walkthrough (Q&A)

Question: Why does `CALCULATE([Sales], Dim_Product[Price] > Dim_Product[Cost])` fail without the FILTER function?

Formula / Action: Boolean filters in CALCULATE can only compare a column against a static constant value.

Result: Comparing column-to-column requires the row-context of `FILTER(Dim_Product, ...)`.

Explanation: DAX boolean shortcuts only allow `Column = "Value"` or `Column > 100`. To compare two columns, you must use `FILTER(Dim_Product, Dim_Product[Price] > Dim_Product[Cost])`.

Common Mistakes & Limitations

  • Writing `CALCULATE([Total Sales], FILTER(Fact_Sales, Fact_Sales[Status] = "Completed"))`; passing a 10M row Fact table into FILTER causes severe performance lag.
  • Forgetting that `FILTER()` returns a Table, so it cannot be used as a standalone scalar measure without CALCULATE or an iterator.

Keyboard Shortcuts

ActionWindowsMac
Format DAX QueryShift + Enter for indentationShift + Enter
Quick measure filteringRight-click Field -> New Quick MeasureNew Quick Measure

Pro Tips & Modern Alternatives

  • For simple column filtering, use boolean syntax `CALCULATE([Sales], Products[Color] = "Red")` which VertiPaq optimizes without row-by-row iteration.
  • Only use `FILTER()` when evaluating a measure condition or comparing multiple columns.