DAX Calculate function with and without FILTER

后端 未结 4 1786
庸人自扰
庸人自扰 2020-12-29 09:02

What is the difference in results of CALCULATE function if we use it with and without FILTER function. Suppose we have those two measures:

Measu         


        
4条回答
  •  温柔的废话
    2020-12-29 09:23

    The difference here is that CALCULATE allows simple filters which will replace the existing filter context. In your example, CALCULATE will compute the measure [X] using the existing filter context, except that it removes any existing filter context for FactTable[Color] and replaces it with FactTable[Color] = Red.

    The FILTER function is an iterator, which means it steps through the table (passed in as its first argument) one row at a time and evaluations the expression (second argument) for each row. When you have a FILTER function inside of CALCULATE, it will combine the existing filter context with the results of the FILTER (instead of replacing it like a simple filter argument).

    In general, you want to use simple filters whenever you have a choice as the computation will be more efficient. However, the FILTER function allows you to do much more complex filtering so it still highly useful in cases where simple filters aren't enough.


    Further reading: FILTER() – When, Why, & How to Use It

提交回复
热议问题