Forum Discussion

Herndon_powerbi's avatar
4 years ago
Solved

want to know the difference

what is the difference between CALCULATE(SUM('Fact Sale'[Quantity])) and SUM('Fact Sale'[Quantity])?
  • OwenAuger's avatar
    4 years ago

    @Hi Herndon_powerbi 

     

    The only difference between these expressions is that, in the expression with CALCULATE, context transition occurs before the SUM(...) expression is evaluated.

     

    "Context transition" means all row contexts are converted into equivalent filters.

     

    This means that these expressions would return different results only if one or more row contexts existed, such as if they were evaluated in a calculated column or within the row context of an iterator.

     

    For example, if you created calculated columns with these expressions in (say) a Customer table, the expression with CALCULATE would convert the current row of the Customer into an equivalent filter, and would give you something like the sum of Quantity for that Customer. Without CALCULATE, the expression would return an unfiltered sum of Quantity. 

     

    One thing to note is that a reference to a measure automatically "wraps" the measure's expression in CALCULATE.

     

    This is a good article on this topic:

    https://www.sqlbi.com/articles/understanding-context-transition/

     

    Regards,

    Owen