Skip to content

Chapter 2 of 6

CALCULATE and Filter Manipulation

CALCULATE is the most important function in DAX because it evaluates an expression in a modified filter context. Its basic syntax is CALCULATE(expression, filter1, filter2, ...), where each filter argument can be a Boolean condition, a table expression, or a modifier such as KEEPFILTERS. When a filter argument targets a column that is already being filtered elsewhere, CALCULATE replaces the existing filter on that column rather than adding to it, an effect sometimes called filter shadowing. When CALCULATE is called without any filter arguments, it still transforms the current row context into an equivalent filter context, a behavior used to force measure evaluation within row contexts such as calculated columns.

A family of functions works alongside CALCULATE to remove or preserve filters. ALL removes all filters from a table or column and is commonly used inside CALCULATE to compute ratios unaffected by slicers, such as a percentage of grand total. ALLEXCEPT removes all filters except those on the columns listed, preserving specific filters while clearing others. REMOVEFILTERS performs the same role as ALL but with clearer intent and is the recommended syntax for clearing filters. KEEPFILTERS modifies CALCULATE behavior so that the new filter argument intersects with existing filters instead of replacing them, which is useful for additive filtering logic. ALLSELECTED returns rows visible inside the current visual context while ignoring filters applied outside the visual, making it ideal for percentages of visual totals.

Other functions alter how relationships propagate filters. USERELATIONSHIP activates an inactive relationship during a CALCULATE evaluation, allowing measures to query through alternate paths such as order date versus ship date. CROSSFILTER temporarily changes the filter direction of a relationship to None, OneWay, or BothWay for the duration of a calculation. Together, these functions give DAX authors precise control over the filter environment, enabling complex analytical logic without altering the underlying data model.

All chapters
  1. 1Foundations of DAX and Calculation Types
  2. 2CALCULATE and Filter Manipulation
  3. 3Iterator, Aggregation, and Lookup Functions
  4. 4Time Intelligence and Date Tables
  5. 5Data Modeling, Relationships, and Schemas
  6. 6Performance, Storage Modes, and Security

Drill it

Reading is not remembering. These come from the Power Bi Dax Fundamentals deck:

Q

What is a DAX measure?

A calculated formula created using DAX that is evaluated at query time based on filter context. Measures return dynamic values depending on the filters applied...

Q

How does filter context work in DAX?

Filter context is the set of filters applied to a calculation, generated by slicers, visuals, page-level filters, or row-level security. It determines which row...

Q

What does the CALCULATE function do?

CALCULATE evaluates an expression in a modified filter context. It can add, replace, or remove filters on specified columns, overriding the existing filter cont...

Q

What is the syntax for CALCULATE?

CALCULATE(, , , ...). The expression is evaluated after applying all listed filter arguments, which can be boolean expressions, table expressions, or KEEPFILTER...