# CALCULATE() - Blocking Semantics

• ### Question

• Hello,

In this article (link below) CALCULATE() function is described to perform 4 operations. The author uses a new term to me "blocking semantics" . What exactly is blocking semantics  in this context?

The Logic behind the Magic of DAX Cross Table Filtering

Calculate function performs the following operations:
1.       Create a new filter context by cloning the existing one.
2.       Move current rows in the row context to the new filter context one by one and apply blocking semantics against all previous tables.
3.       Evaluate each setfilter argument in the old filter context and then add setfilter tables to the new filter context one by one and apply blocking semantics against all tables that exist in the new filter context before the first setfilter table is added.
4.       Evaluate the first argument in the newly constructed filter context.

Monday, March 20, 2017 2:39 PM

• Hi Natasha,

Blocking semantics means a filter context which will be blocking based on inconsistent. I will introduce it based on the the given example in the article.

1. The first argument of AverageX sets a month in row context.  When it comes to Calculate, it first removes the month from row context and adds it to filter context, it does not block anything. So there is no blocking semantics.

2. Next Calculate adds Store[Country] = “USA” to filter context which blocks existing filter Store[Country] = “Canada”. "blocking existing filter Store[Country] = “Canada”" is an application of blocking semantics.

If you have other issues, don't hesitate to let me know.

Best Regards,
Angelia

MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

Tuesday, March 21, 2017 3:17 AM
• This is a very complicated way of explaining CALCULATE. Basically, the four steps in the execution of CALCULATE are:

1. Create a filter context (which isn't a big deal when coming from a query context, but makes a lot of difference when coming from a row context)

2. In this context, remove all filters on any column referenced in any of the filter arguments (when a whole table is referenced, this applies to all columns in the table)

3. Apply all filters in the filter arguments instead

4. Evaluate the first argument in the new context

Step 2 can be suppressed using the KEEPFILTERS function. As an illustration of the latter, a common scenario is to show a list of e.g. the top 10 customers. You can do this using the TOPN function in a filter argument of CALCULATE (say, CALCULATE([TotalSales], TOPN(10, Customer, [TotalSales]))  ), but this measure will return the total sales of the top 10 customers for each customer in the report, because the filter on customer is removed from the context. But with CALCULATE([TotalSales], KEEPFILTERS(TOPN(10, Customer, [TotalSales]))) the measure only return a result for a customer when that customer is in the top 10.

Tuesday, March 21, 2017 1:36 PM

### All replies

• Hi Natasha,

Blocking semantics means a filter context which will be blocking based on inconsistent. I will introduce it based on the the given example in the article.

1. The first argument of AverageX sets a month in row context.  When it comes to Calculate, it first removes the month from row context and adds it to filter context, it does not block anything. So there is no blocking semantics.

2. Next Calculate adds Store[Country] = “USA” to filter context which blocks existing filter Store[Country] = “Canada”. "blocking existing filter Store[Country] = “Canada”" is an application of blocking semantics.

If you have other issues, don't hesitate to let me know.

Best Regards,
Angelia

MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

Tuesday, March 21, 2017 3:17 AM
• Thanks
Tuesday, March 21, 2017 1:27 PM
• This is a very complicated way of explaining CALCULATE. Basically, the four steps in the execution of CALCULATE are:

1. Create a filter context (which isn't a big deal when coming from a query context, but makes a lot of difference when coming from a row context)

2. In this context, remove all filters on any column referenced in any of the filter arguments (when a whole table is referenced, this applies to all columns in the table)

3. Apply all filters in the filter arguments instead

4. Evaluate the first argument in the new context

Step 2 can be suppressed using the KEEPFILTERS function. As an illustration of the latter, a common scenario is to show a list of e.g. the top 10 customers. You can do this using the TOPN function in a filter argument of CALCULATE (say, CALCULATE([TotalSales], TOPN(10, Customer, [TotalSales]))  ), but this measure will return the total sales of the top 10 customers for each customer in the report, because the filter on customer is removed from the context. But with CALCULATE([TotalSales], KEEPFILTERS(TOPN(10, Customer, [TotalSales]))) the measure only return a result for a customer when that customer is in the top 10.

Tuesday, March 21, 2017 1:36 PM