CALCULATE DAX Function (Filter)  Context Transition

Evaluates an expression in a context modified by filters.

Syntax

CALCULATE ( <Expression> [, <Filter> [, <Filter> [, … ] ] ] )
Parameter Attributes Description
Expression

The expression to be evaluated.

Filter Optional
Repeatable

A boolean (True/False) expression or a table expression that defines a filter.

Return values

Scalar A single value of any type.

The value is the result of the expression evaluated in a modified filter context.

Remarks

Every filter argument can be either a filter removal (such as ALL, ALLEXCEPT, ALLNOBLANKROW), a filter restore (ALLSELECTED), or a table expression returning a list of values for one or more columns or for an entire expanded table.

When a filter argument has the form of a predicate with a single column reference, the expression is embedded into a FILTER expression that filters all the values of the referenced column. For example, the predicate shown in the first expression is internally converted in the second expression.

CALCULATE ( 
    <expression>,
    table[column] = 10
)

CALCULATE ( 
    <expression>,
    FILTER ( 
        ALL ( table[column] ),
        table[column] = 10
    )
)

A filter argument overrides the existing corresponding filters over the same column(s), unless it is embedded within KEEPFILTERS.

CALCULATE evaluation follow these steps:

  1. CALCULATE evaluates all the explicit filter arguments in the original evaluation context. This includes both the original row contexts (if any) and the original filter context. All explicit filter arguments are evaluated independently in the original evaluation context. Once this evaluation is finished, CALCULATE starts building the new filter context.
  2. CALCULATE makes a copy of the original filter context to prepare the new filter context. It discards the original row contexts, because the new evaluation context will not contain any row context.
  3. CALCULATE performs the context transition. It uses the current value of columns in the original row contexts to provide a filter with a unique value for all the columns currently being iterated in the original row contexts. This filter may or may not contain one individual row. There is no guarantee that the new filter context contains a single row at this point. If there are no row contexts active, this step is skipped. Once all implicit filters created by the context transition are applied to the new filter context, CALCULATE moves on to the next step.
  4. CALCULATE evaluates the CALCULATE modifiers USERELATIONSHIP, CROSSFILTER, ALL, ALLEXCEPT, ALLSELECTED, and ALLNOBLANKROW. This step happens after step 3. This is very important, because it means that one can remove the effects of the context transition by using ALL. The CALCULATE modifiers are applied after the context transition, so they can alter the effects of the context transition.
  5. CALCULATE evaluates all the explicit filter arguments in the original filter context. It applies their result to the new filter context generated after step 4. These filter arguments are applied to the new filter context once the context transition has happened so they can override it, after filter removal – their filter is not removed by any ALLxxx modifier – and after the relationship architecture has been updated. However, the evaluation of filter arguments happens in the original filter context and it is not affected by any other modifier or filter within the same CALCULATE function.

The filter context generated after point (5) is the new filter context used by CALCULATE in the evaluation of its expression.

Related articles

Learn more about CALCULATE in the following articles:

  • Context Transition and Filters in CALCULATE

    This article explains how the context transition interacts with the filter arguments of a CALCULATE function in DAX. This is important in order to avoid unexpected results with complex calculations made in filter arguments. » Read more

  • Filter Arguments in CALCULATE

    A filter argument in CALCULATE is always an iterator. Finding the right granularity for it is important to control the result and the performance. This article describes the options available to create complex filters in DAX. » Read more

  • Order of Evaluation in CALCULATE Parameters

    DAX is the new language used by PowerPivot and Analysis Services in Tabular mode and it resembles the syntax of Excel formula and it can be considered a functional language. You do not have iterative statements, but you can run iterative functions like, for example, SUMX and FILTER. The most important functions in DAX are […] » Read more

  • Using OR conditions between slicers in DAX

    This article describes how to implement in DAX a logical OR condition between the selection of two slicers of a Power BI report or of a PivotTable in Excel. By default, when relying on more than one slicer they are considered in an AND condition. » Read more

Related functions

Other related functions are:

Last update: Dec 1, 2018   » Contribute   » Show contributors

Contributors: Alberto Ferrari, Marco Russo

MSDN documentation: https://msdn.microsoft.com/en-us/query-bi/dax/calculate-function-dax

DAX Conventions
Context Transition

This function performs a Context Transition if called in a Row Context. Click to read more.

Row Context

This expression is executed in a Row Context. Click to read more.

Iterator

Not recommended

The use of this function is not recommended. See Remarks and Related functions for alternatives.

Not recommended

The use of this parameter is not recommended.

Deprecated

This function is deprecated. Jump to the Alternatives section to see the function to use.

Deprecated

This parameter is deprecated and its use is not recommended.

Contribute

Want to improve the content of CALCULATE? Did you find any issue? Please, report it us!
All submissions will be evaluated for possible updates of the content.