Forum Discussion

WJ876400's avatar
WJ876400
Helper IV
6 years ago
Solved

Varience

Hi   I have two columns, a target and actual. I want to create another column which is a calculation and then base some conditional formatting off the new column.   For the new column variance, t...
  • neatdot's avatar
    6 years ago

    In Power Query:

     

    = Table.AddColumn(<previous step>, "Variance", each ( [Actual] - [Target] ) / [Target])

     

    Or in DAX:

     

    Variance = DIVIDE ( Table[Actual] - Table[Target], Table[Target] )

     

    In the DAX version, remember to replace Table with your actual table name.

     

    In the visual you base off the column, you will need to use conditional formatting to apply a colour based on the value of Variance. 

     

    However, it's worth pointing out that a more optimal solution would use measures. You should create measures for Target and Actual, then a measure for Variance (rather than a calculated column). The reason for this is that calculated columns take up space in your data model, and also may not produce the correct results depending on how thay are aggregated. A measure will (iff well designed) always produce the correct answer no matter how you aggregate.