Forum Discussion

MP_123's avatar
MP_123
Microsoft Employee
9 years ago
Solved

calculate with filter

hi, i have two tables related by ID in the second table, i have ID column and string column for example ID    String 1     ab 2     abc   with calculated measure, i concatenate chars together...
  • v-ljerr-msft's avatar
    9 years ago

    MP_123


    only when i write 'ab' instead of the measure's valuee, the query result is correct.


    As ConcatenateMEASURE is within the FILTER function, it will be evaluated for each row of the table2. So the result of ConcatenateMEASURE will be "ab" and "abc", not "ab".

     

    In this scenario, using VAR function (whose value do not change once evaluated in the current context, even if the variable is referenced in another expression) should solve this issue. The formula below is for your reference.

    =
    VAR ConcatenateValue = ConcatenateMEASURE
    RETURN
        CALCULATE (
            SUM ( 'table1'[measure_from_table1] ),
            FILTER ( table2, string = ConcatenateValue )
        )

     Regards