20.3The Calendar and filter modifiers

Formats and their sort columns make visuals readable. They have a downside. Each column of the Calendar can carry a filter, and a filter modifier that does not name one of them returns an unexpected result, without any error message. For DAX, this result is correct, since it follows the filters that remain. It is the question asked that does not get its answer.

20.3.1The visual adds the sort column

Take a visual by “Month,” sorted by “Month Sort.” You want the share of each month in the total:

Month Share = DIVIDE( [Revenue], CALCULATE( [Revenue], ALL( Calendar[Month] ) ) )
Power BI accepts this DAX foryes, Measureyes, Calculated columnno, Calculated tableno, Virtual table
Table visual, The “Month Share” measure by “Month,” with ALL( Calendar[Month] )
MonthMonth Share
Jan'24100%
Mar'24100%
May'24100%
Sep'24100%
Nov'24100%
Jan'25100%
Feb'25100%
Mar'25100%
May'25100%
Jul'25100%
Sep'25100%
Dec'25100%
Total100%

This is a reproduction of the Power BI interface for teaching purposes. It differs from the real interface.

Each month weighs 100%. If you have already run into this result, rest assured, the formula is not badly written. The cause is a column that the visual does not show. The Diagnostic also starts from this symptom, and guides you step by step.

“Month Sort” is not a column that Power BI creates on its own. We added it to our Calendar, and we sorted “Month” by it. To arrange the rows, Power BI then adds “Month Sort” to the calculation of the visual.

So the Jan’24 row carries two filters, “Month” = Jan’24 and “Month Sort” = 202401.

ALL( Calendar[Month] ) provides only months. CALCULATE replaces the filter on “Month” with them, but the filter on “Month Sort” remains, and Jan’24 is divided by itself.

This is not specific to ALL. REMOVEFILTERS( Calendar[Month] ) and ALLSELECTED( Calendar[Month] ) also return 100%. Each one deals only with the “Month” column, and the filter on “Month Sort” remains. A filter written in CALCULATE, like Calendar[Month] = "Jan’24", behaves the same way. It replaces the filter on “Month,” the one on “Month Sort” remains, and the Mar’24 row becomes blank, because it keeps “Month Sort” = 202403. CALCULATE then looks for the days that are both in Jan’24 and in month 202403, and finds none.

Name the sort column along with its format:

Month Share = DIVIDE( [Revenue], CALCULATE( [Revenue], ALL( Calendar[Month], Calendar[Month Sort] ) ) )
Power BI accepts this DAX foryes, Measureyes, Calculated columnno, Calculated tableno, Virtual table
Table visual, The “Month Share” measure by “Month,” with ALL on “Month” and “Month Sort”
MonthMonth Share
Jan'2414.7%
Mar'248.8%
May'245.9%
Sep'245.9%
Nov'248.8%
Jan'2511.8%
Feb'258.8%
Mar'258.8%
May'258.8%
Jul'258.8%
Sep'255.9%
Dec'252.9%
Total100%

This is a reproduction of the Power BI interface for teaching purposes. It differs from the real interface.

With REMOVEFILTERS or ALLSELECTED, the fix is the same, name “Month” and “Month Sort.”

ALLEXCEPT takes the other road. It names the columns to keep, and CALCULATE replaces the filters of all the other columns of the Calendar, sort column included. Take the same visual, under a “Year” slicer that keeps 2024, and the share of each month in its year:

Share of the Year = DIVIDE( [Revenue], CALCULATE( [Revenue], ALLEXCEPT( Calendar, Calendar[Year] ) ) )
Power BI accepts this DAX foryes, Measureyes, Calculated columnno, Calculated tableno, Virtual table
In plain words

“I want the revenue of the month, divided by that of its whole year, whatever the month and its sort column.”

On the Jan’24 row, “Month Sort” loses its filter without being named. The denominator, the figure you divide by, is 750,000, all the sales of 2024, and Jan’24 weighs 33.3%.

The trap moves to the other side. A column you forget to name loses its filter too. Without Calendar[Year] in ALLEXCEPT, the slicer’s filter would be replaced, and the denominator would count both years, 1,700,000. With ALLEXCEPT, name the columns to keep, including those of the slicers.

“Month” is not the only column concerned. In our Calendar, we sorted four columns by another one:

  • “Month” by “Month Sort”;
  • “Quarter” by “Quarter Sort”;
  • “Week” by “Week Sort”;
  • “Month Name” by “Month Number.”

A visual by “Week” thus takes “Week Sort” along, and a visual by “Month Name” takes “Month Number” along. The modifier then names the column of the visual and its sort column.

The rest of this lesson is part of izyDAX Pro

You have just read the first section. The next 3, their animations, the exercises and the summary are waiting for you with izyDAX Pro, in a single payment.