DAX CALCULATE Function
The most important, versatile, and transformative function in DAX.
CALCULATE( Expression, [Filter1], [Filter2], ... )Overview
CALCULATE evaluates an expression within a modified filter context. It is the only function in DAX that can create, modify, or override existing filter context.
When CALCULATE evaluates, it performs two critical operations: 1) If called within a row context, it converts the row context into an equivalent filter context (Context Transition). 2) It applies new filter arguments, replacing existing filters on specified columns or intersecting with them if wrapped in KEEPFILTERS.
Enterprise Revenue =
CALCULATE(
SUM(Sales[Revenue]),
Customers[Segment] = "Enterprise"
)When to use CALCULATE
- Changing the filter context for a calculation: a specific segment, a fixed period, ignoring a slicer.
- Building ratios such as percent of total, where the denominator needs different filters from the numerator.
- Triggering context transition when you need a measure evaluated for the current row of an iterator.
Worked examples
Percent of all products
% of All Products =
DIVIDE (
[Total Sales],
CALCULATE ( [Total Sales], REMOVEFILTERS ( 'Product' ) )
)The denominator removes filters from the Product table only, so slicers on date or region still apply. Removing filters from the whole fact table is a common bug — see the ALL vs REMOVEFILTERS guide.
Keeping the user's selection with KEEPFILTERS
Red Sales =
CALCULATE ( [Total Sales], KEEPFILTERS ( 'Product'[Color] = "Red" ) )Without KEEPFILTERS, the Color filter replaces any color the user selected, so the measure shows red sales even when the slicer says blue. KEEPFILTERS intersects the two, returning blank for blue.
Common mistakes
- Overwriting existing slicer selections unexpectedly without using KEEPFILTERS.
- Misunderstanding how multiple filters interact (comma-separated filters act as AND, not OR).
- Failing to understand that measures automatically invoke an implicit CALCULATE.
Performance notes
CALCULATE is not slow in itself, but its filter arguments decide how much work the engine does. Filters on columns (Product[Color] = "Red") are cheap; FILTER over a whole table forces row-by-row evaluation. Inside an iterator, every CALCULATE (including the implicit one around a measure reference) triggers a context transition per row — fine on a small dimension, expensive on a large fact table.
Frequently asked questions
- Why does CALCULATE ignore my slicer?
- A filter argument on a column replaces existing filters on that same column. If the user filtered Color and your CALCULATE sets Color, the user's filter is overwritten. Use KEEPFILTERS to intersect instead.
- Are multiple CALCULATE filters AND or OR?
- AND. Each filter argument is applied together. For OR across different columns, use a single FILTER over the combination of columns or a table filter built with UNION/TREATAS.
- What is context transition?
- When CALCULATE runs inside a row context (an iterator or calculated column), it turns the current row into an equivalent filter context. Every measure reference has an implicit CALCULATE, so referencing a measure inside SUMX triggers it for each row.