128 Practical PowerPivot & DAX Formulas for Excel 2010
T
his is the core of DAX. If you understand what’s happening, you understand DAX.
The ALL() function, in the preceding example, is acting as the filter or SetFilter
parameter of the CALCULATE() function. ALL() is overriding the current filter
context. The filter parameter is optional and you can have more than one. Here,
it’s telling the pivot table to ignore any filter on country (for example, Austria) that
the user may choose. It’s always going to show the figure for all countries—thanks
to the ALL() function. Why might this be very useful? There are a number of
important reasons. For example, you can have highly customized and flexible
measures that display exactly what you want. Or, you might want to control the
scope of the end user—so that, even if they add countries and filter on a particular
country, the figures they see are still for all countries. You are programmatically
overriding the user actions in the GUI. Or you might have measures based on this
measure, and those new measures require the data for all countries.
9. Let’s experiment. Change the formula as follows:
=CALCULATE(SUM('Order Details'[Quantity]),ALL(Orders[Year]))
Now as you filter, the Year slicer is totally ignored, but the Country filter is
operative again. Some of the possible results are shown in Figure 4-16 (No filter),
Figure 4-17 (Year filter), Figure 4-18 (Country filter), and Figure 4-19 (Year
and Country filter). Take some time to digest the figures and understand what is
happening.
Figure 4-15 Year and Country filter context 1/3