Forum Discussion

Credo's avatar
Credo
Helper I
7 years ago
Solved

VAR different result than without it

I've been slowly learning to use variables however I've run into a result that I dont understand    I have a table with Sales by Manager that is filtered by TopN 10 Managers based on sales.    I ...
  • OwenAuger's avatar
    7 years ago

    Hi Credo

     

    When a variable is defined with VAR, it is evaluated in the context where it is defined, then it is effectively a constant when used in any subsequent expressions. Currently there is no way to define a measure locally within another measure, so I would recommend sticking with Sum of Sales as a separate measure and referencing that within Sales Top 10.

     

    To explain further, in your second example, after the variable Sales is defined as SUM ( 'FactSales'[Sales] ), the expression CALCULATE ( Sales; ALL ( 'FactSales'[Manager] ) ) gives exactly the same result as Sales, since Sales is effectively a constant, and modifying filters makes no difference to a constant.

     

    Regards,

    Owen