Forum Discussion

frodriguezw's avatar
frodriguezw
Frequent Visitor
7 years ago
Solved

Calculate Measure gets different results depending on filter

Hi,   I'm new to this forum, so I really appreciate your help here!   I downloaded Sales and Marketing Sample PBIX which contains VanArsdel Sales. I have the following table:     This is...
  • Arentir's avatar
    7 years ago

    Hi frodriguezw

    Welcome to the wonderful world of DAX!

     

    It is an interesting one. What you see is all due to filter context.

    I won't go into the detail of evaluation context, if you are not too familiar with this I strongly suggest that you look into the ressources I am putting at the bottom of this post.

     

    Calculate is a function that modify the filter context. In your matrix, your filter context is Manufacturer, ie each row should compute the total unit of Abbas, Aliqui, etc...

    But calculate changes the rule of the game and discards your natural filter context:

    Measure 1: You have a filter context on Manufacturer (table row), but your calculate will only computes when IsVanArsdel = "Yes". Which is true only for Manufacturer = VanArsdel. Conclusion: you have no value but for this row

     

    Measure 2: You have a filter context on Manufacturer (table row), but your calculate does too as this as you have specify this very column ("ALL('Product')[Manufacturer])). Therefore it will ignore your table row completely and give you the result of your condition for any manufacturer on rows. Conclusion: your table row is ignored and the value for VanArsdel is repeated for each row.

     

    For more on Evaluation context ( Filter Context + Row Context):

    A true master of DAX and great introduction

    https://www.youtube.com/watch?v=klQAZLr5vxA (from 01:15:00)

    https://www.youtube.com/watch?v=6ncHnWMEdic&t=2403s (the whole thing)

     

    https://www.sqlbi.com/articles/row-context-and-filter-context-in-dax/