Indeed, the compact syntax (also referred to as a Boolean filter) is translated into the extended syntax by the engine as part of the evaluation of an expression. CALCULATE filters are tables. Even though they can be written as Boolean expressions, they are always interpreted as tables.

A common practice in computing percentages is to divide a given measure by the same measure where certain filters are removed. For example, a proper expression for the percentage of sales against all colors would look like this:

ALL returns a table containing all the colors; this table represents the valid colors to be used in the new filter context of CALCULATE. Forcing all the colors to be visible is equivalent to removing any and all filters from the Color column.

This description consists of two sentences: both are wrong. This is not to say that the description is completely wrong. It is accurate most of the time, but not always. The correct description of the behavior of ALL in the PctOverColors measure above is much simpler indeed:

In the correct description there is no statement about the result of ALL – in fact, it does not return anything – and there is no equivalence between a table with all values and the removal of a filter. The reality is much simpler: filters are removed. At first sight, it looks like a very pedantic detail. However, this small difference may yield very different results when used in more complex DAX expressions.

As an example, let us consider these two measures: NumOfProducts computes the total number of products, whereas NumOfProductsSold only counts products which have been sold, by leveraging table filtering.

NumOfProducts is straightforward, whereas NumOfProductsSold requires additional DAX knowledge because it is based on table expansion. Because a table is being used as a filter parameter in CALCULATE, the filter context contains all the columns of the expanded version of Sales. If you are not familiar with expanded tables, you will find additional resources in Chapter 10 of the book, The Definitive Guide to DAX.

So far, everything works exactly as expected. What happens if there is the need to compute the value in the current context against the grand total? For example, the number of red products divided by the total number of products, and the number of red products sold against the total number of products sold, producing this report:

Surprisingly, this code does not produce the report above. Instead, the result looks like that:

In the PercOfProductsSold column, the percentage for red products is wrong. Here’s an explanation. First, an understanding of the subtle difference between using ALL as a filter remover and using ALL as a table function is crucial. Let us start from the beginning:

ALL is a table function that returns all the rows of a table or of a set of columns. This is the correct behavior of ALL whenever that result is actually required. In the very specific case of CALCULATE filters – and only in this specific case – ALL is not used to retrieve values from a table. Instead, ALL is used to remove filters from the filter context. Though the function name is the same, the semantics of the function is completely different.

ALL, when used as a CALCULATE filter, removes a filter. It does not return a table result.
Using a different name for the different semantics of ALL would have been a good idea. A very reasonable name would have been REMOVEFILTER.

Let us understand it better, by examining the denominator of PercOfSoldProducts:

In this case, ALL is a filter parameter of CALCULATE. As such, it acts as a REMOVEFILTER, not as an ALL. When CALCULATE evaluates the filter in the denominator, it finds ALL. ALL requires the removal of any filters from the expanded Sales table, which includes Product[Color]. Thus, the filter is removed but no result is ever returned to CALCULATE.

Because no result is returned, the expanded Sales table is not used as a filter by CALCULATE. At the risk of being pedantic, here is the same code with the new name for ALL:

Using ALL ( Sales ) does not mean, “filter using all the rows in Sales”. It means, “remove any filters from Sales”. With this small change in how the formula reads, it is now clear that the number of products is the total number of products if no filter is ever applied. Thus, the denominator always computes 2,517 instead of 1,170. This explains why the percentage goes from 4.36% to 2.03%.

This behavior definitely seems strange. Nevertheless, as is often the case with DAX, the behavior is not strange at all, that’s just the way it is. If it does not meet our expectations – then the problem is our limited knowledge, not the behavior itself.

At this point, it is interesting to look at how to properly write the formula. As shown, ALL is not enough because it does not return its value, it only removes filters. An option is to still use ALL, but move it inside an outer CALCULATETABLE. By doing this, ALL still behaves like a REMOVEFILTER, but CALCULATETABLE forces the result back:

Using CALCULATETABLE outside of ALL looks like a trick, but it is not. It actually changes the semantics of the formula, making it explicit that the result of ALL ( Sales ) is needed in order to filter the formula. A similar behavior can be obtained with a less elegant formula:

In this case it is FILTER that forces the result of ALL ( Sales ) to be returned, by using a dummy filter with a condition that always evaluates to TRUE.

It is worth noting that all the tables used as filter arguments are, indeed, expanded tables. Therefore, the action of removing filters impacts not only the base table but the entire expanded table. ALL ( Sales ) acts as REMOVEFILTER on the expanded version of Sales, removing filters from the table and from all related dimension.

This behavior is particularly important in the case of ALLEXCEPT. Consider the following measure:

One might think that ALLEXCEPT removes all filters from the columns in the Sales table except for the ProductKey column. However, the behavior is noticeably different. ALLEXCEPT removes filters from the expanded version of Sales, which includes all the tables that can be reached through a many-to-one relationship starting from Sales. This includes customers, dates, stores, and any other dimension table.

The following syntax prevents ALLEXCEPT from removing filters from a specific table: