Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Comparison using IF for multiple conditions

Hello,

I have the following table loaded in Power Query and i have a measure which compares the "Calculated value" to the "Input value" for each row and then i used conditional formatting in the Calculated value column.

I am trying to do the following:

If status = 0, compare the calculated and input value. If equal, then set to 0, otherwise set to 1.

If status = 1, compare the calculated and input value. If equal, then set to 2, otherwise set to 3.

 

Here is my current measure but it only checks if the Calculated vs. Input values are same. Any help is much appreciated!

 

Value Check = 
IF (
    ROUND ( [Calc value Measure], 0 )
        <> ROUND ( [Input value Measure], 0 ),
    1,
    0
)

 

 

Document IDCalculated valueInput valueStatus
39982439.172439.170
40501176.561176.561
4050791024.45791024.450
406011810.2518100
413912352.0312352.031
414581045.8681045.860
4149365.95545.951
41574509.884513.880
416052011520110
41602922.4542.40
41649592.569592.560
416632471.6787441.670
41876793.626793.620
418733938.133938.10
41874781.1443901
418714124135381
42481043101543100
43144598.014598.011
447478597785970
4481310904.7394904.730
4487372359.04372359.040
4495114411440
4685734125.54734125.540
4688407368240736820
46911456831756831
4813180000841000
48324372334372330
4997163683116368310
  • This measures should do what you're looking for.

    # Value Check = 
    VAR thisStatus = SELECTEDVALUE('Table'[Status])
    VAR thisCalculatedValue = SELECTEDVALUE('Table'[Calculated value])
    VAR thisInputValue = SELECTEDVALUE('Table'[Input value])
    
    RETURN
    SWITCH(
        TRUE(),
        thisStatus = 0, IF(thisCalculatedValue = thisInputValue, 0, 1),
        thisStatus = 1, IF(thisCalculatedValue = thisInputValue, 2, 3)
    )

    If this solves your problem, please accept this as the solution.

1 Reply

  • AUaero's avatar
    AUaero
    Responsive Resident

    This measures should do what you're looking for.

    # Value Check = 
    VAR thisStatus = SELECTEDVALUE('Table'[Status])
    VAR thisCalculatedValue = SELECTEDVALUE('Table'[Calculated value])
    VAR thisInputValue = SELECTEDVALUE('Table'[Input value])
    
    RETURN
    SWITCH(
        TRUE(),
        thisStatus = 0, IF(thisCalculatedValue = thisInputValue, 0, 1),
        thisStatus = 1, IF(thisCalculatedValue = thisInputValue, 2, 3)
    )

    If this solves your problem, please accept this as the solution.