hello,
I am learning the calculate function in dax…
I see that I can have an expression to simply filter without using the filter function.
In some examples I see filter function used inside calculate.
Question:
Inside calculate, how do I know when to use filter function or not?
thanks
@arkiboys Writing
CALCULATE ( [Measure], Table[Column] = "Something" )
is internally translated to
CALCULATE ( [Measure], FILTER ( ALL ( Table[Column] ), Table[Column] = "Something" ) )
So even if you don’t write FILTER explicitly it is just added automatically.
does this mean there is never a need to use filter in calculate because it happens automatically in calculate?
thanks
If you are writing simple statements Table[Column] = “Something” then no, but if you want to first filter the column(s) based on some Measure or complex condition then you need to use FILTER, also if you use FILTER you can store a part of the code in a variable outside CALCULATE when it is suitable and the code is more readable.
perhaps it is always best to use filter function then?
thanks
I don’t think so, if a condition doesn’t require FILTER and you still explicitly mention it then it goes against the “KISS - Keep it simple, stupid” prinicple of programming.
If it is not needed then the predicate statement Table[Column] = “Something” is more clean and readable approach.
thank you