Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

FILTER vs CALCULATETABLE based on Boolean Expression

Hi Experts, I am looking to understand why is that for FILTER to work in my code, I have to used DATESBETWEEN as a true/ false expression whereas for CALCULATETABLE to work similarly, it needs to be...
  • Anonymous's avatar
    Anonymous
    5 years ago

    That's because the second argument to FILTER must ALWAYS be a logical condition (or castable to it) that operates for each row of the table in the first argument (FILTER is an iterator) and all CALCULATETABLE's arguments must ALWAYS be tables. DATESBETWEEN returns a table.

     

    Even the seemingly logical condition in:

     

    calculatetable( A, T[Col] = Value )

     

    is internally translated into:

     

    calculatetable( A, Filter( All(T[Col]), T[Col] = Value ).

     

    So the "logicals" under CALCULATETABLE are just syntactic sugar.

  • Anonymous's avatar
    Anonymous
    5 years ago

    If you read the ultimate source of knowledge on DAX, which is The Book, you'll find the explanation of the use of the seemingly "logical expressions" under CALCULATETABLE that I gave you. No, what the docs mention is syntactic sugar. Only.

     

    Check this out: How CALCULATE works in DAX - SQLBI

     

    Well, Microsoft is just not telling you the whole truth but The Italians do.