Skip to content

CALCULATE and deliberate filter changes

CALCULATE evaluates a scalar expression under modified filter context. CALCULATETABLE does the corresponding job for a table expression.

Replacement versus intersection

North Revenue =
CALCULATE ( [Revenue], DimRegion[Region] = "North" )

A Boolean filter normally replaces an existing filter on the same column. With South already selected, this measure evaluates North instead and returns 4100 in the unrestricted-date/product model.

North Within Selection =
CALCULATE ( [Revenue], KEEPFILTERS ( DimRegion[Region] = "North" ) )

KEEPFILTERS intersects with the existing Region filter. South intersected with North contains no rows, so this measure is BLANK, not 4100. Run query 06 to see selected Revenue 5400, replacement 4100, intersection BLANK.

Removing only the intended dimension

All Products Revenue =
CALCULATE ( [Revenue], REMOVEFILTERS ( DimProduct ) )

The denominator intentionally removes filters on DimProduct, including Category. It retains Region and Date. Under North/Laptop, Revenue is 3000 and All Products Revenue is 4100. Removing every model filter would answer a different comparison.

REMOVEFILTERS is a filter modifier, not a standalone table you can EVALUATE. Use table-returning functions when you actually need a rowset.

Choose the narrowest valid filter

Prefer a simple Boolean filter on the intended dimension when that expresses the requirement. Use FILTER for conditions needing row-by-row table evaluation. Boolean filter expressions have restrictions: they reference columns from one table, cannot use measures or nested CALCULATE directly, and only allow certain scalar aggregations/table-scanning patterns.

Do not write an arbitrary measure comparison as a Boolean filter and assume the engine accepts it. Consult the function reference and test a small query.

Exercise: predict both North measures under no Region filter, North, and South. Identify which scenario means "always North" and which means "North within the user's allowed selection."

Reference: CALCULATE and KEEPFILTERS.