DAX Difference between naked SUM and sum wrapped in CALCULATE

前端 未结 3 559
走了就别回头了
走了就别回头了 2021-01-18 06:50

What is the difference between naked SUM and sum wrapped in CALCULATE?

Measure1 = SUM( tab[col1]) )
Measure2 = CALCULATE ( SUM( tab         


        
3条回答
  •  情深已故
    2021-01-18 07:50

    Depends on how you are using the expressions i.e. CALCULATED COLUMN vs MEASURE and in what context. Filter contexts are derived from active filters in your report i.e. SLICERS, CROSS FILTER through visuals themselves and can even be propagated through relationships existing in the model. Used in a calculated column they would yield very different results. See the image below:

    As you can see Ive provided a very basic data set displaying job titles and their respective salaries. When using the expression without the calculate satatement there is no filter context provided and none would be derived implicitly, thus the column would result in the TOTAL sum for the entire 'Salary' field. When we wrap the same expression in a calculate statement we provide a ROW CONTEXT and get the sum for each ROW within the table. Two very different results.

    When used in a measure they would produce identical results. See the image below: This is because the SUM() measure would be wrapped with a CALCULATE implicitly and inherit the same functionality as the MEASURE containing the CALCULATE statement. In this case the tree-map is used as a slicer and is providing a filter context to both measure thus producing identical results.

    This ARTICLE does a great job of explaining row and filter contexts.

    Hope this helps!!

提交回复
热议问题