Forum Discussion

jasanlea's avatar
jasanlea
Regular Visitor
2 years ago
Solved

Subtract two total num values from same column using a filter from other column in the same table

Hi everyone,   I am really new using PowerBi and I am trying to find the way to create a measure using DAX code to receive the result of subtracting two total num values from same column using a fi...
  • talespin's avatar
    2 years ago
    Hi jasanlea ,
     
    Please note that below measure will remove all filters on table and calculate sum for reference value =1 and 2 and subtract them. If it is something else you want then please explain in detail.
     
    testtable4
    -----------
    ReferenceValue2024
    15
    23
     
    Measure
    ------------
    Measure Sub =
    VAR _refVal1 = CALCULATE(SUM(TestTable4[2024]), REMOVEFILTERS(TestTable4[ReferenceValue]), TestTable4[ReferenceValue] = 1)
    VAR _refVal2 = CALCULATE(SUM(TestTable4[2024]), REMOVEFILTERS(TestTable4[ReferenceValue]), TestTable4[ReferenceValue] = 2)

    return IF(HASONEFILTER(TestTable4[ReferenceValue]), SELECTEDVALUE(TestTable4[2024]), _refVal1 - _refVal2)