Forum Discussion
DAX Code Explanation
- 11 months ago
Hi blazgaj , Thank you for reaching out to the Microsoft Community Forum.
The difference between your TEST and TEST_2 measures comes down to how filter context is managed in DAX, especially with ALLEXCEPT. In TEST, using three separate CALCULATE blocks for each scenario means each block keeps the original filter context from your visual, including Division. So, when your visual slices by Division, TEST changes per row because it sees the Division filter.
In TEST_2 you’ve used ALLEXCEPT to clear all filter context on the table except for BU Code. That means any context applied for Division by your visual is ignored, so every row shows the same result regardless of which Division is selected. This mimics the behavior of ALL rather than preserving context for Division; ALLEXCEPT only keeps BU Code and drops everything else. That’s why your TEST_2 doesn’t break down by Division. To do what TEST does, don’t use ALLEXCEPT for business logic relying on multiple contexts, instead, use separate variables or CALCULATE blocks for each logical segment to keep filter context.
Hi blazgaj , Thank you for reaching out to the Microsoft Community Forum.
The difference between your TEST and TEST_2 measures comes down to how filter context is managed in DAX, especially with ALLEXCEPT. In TEST, using three separate CALCULATE blocks for each scenario means each block keeps the original filter context from your visual, including Division. So, when your visual slices by Division, TEST changes per row because it sees the Division filter.
In TEST_2 you’ve used ALLEXCEPT to clear all filter context on the table except for BU Code. That means any context applied for Division by your visual is ignored, so every row shows the same result regardless of which Division is selected. This mimics the behavior of ALL rather than preserving context for Division; ALLEXCEPT only keeps BU Code and drops everything else. That’s why your TEST_2 doesn’t break down by Division. To do what TEST does, don’t use ALLEXCEPT for business logic relying on multiple contexts, instead, use separate variables or CALCULATE blocks for each logical segment to keep filter context.
v-hashadapu This is a great explanation.