Forum Discussion

blazgaj's avatar
blazgaj
Regular Visitor
10 months ago
Solved

DAX Code Explanation

Hello, could somebody please explain me why measure TEST_2 do not act the same way as TEST: The goal is to calcuate sum of 3 months with bunch of filters: TEST (correct one): TES...
  • v-hashadapu's avatar
    10 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.

     

    ALL function (DAX) - DAX | Microsoft Learn

    ALLEXCEPT function (DAX) - DAX | Microsoft Learn