powerbiswitch-statementdax

Power bi DAX query SWITCH error not working


Hi I am trying to add colour to my chart to be red if above UCL or Green if below LCL. I keep getting this error. Any advice please?

`Query (2, 2) The syntax for 'SWITCH' is incorrect. (RateColour =

SWITCH( TRUE, MAX('UCL Table'[rate]) > MAX('UCL Table'[UCL]), "#FF0000",
MAX('UCL Table'[rate]) < MAX('UCL Table'[LCL]), "#00C853", "#A0A0A0"
)).`

Thanks


Solution

  • You need to use the TRUE() function, not the literal TRUE:

    RateColour =
    SWITCH(
        TRUE(),
        MAX('UCL Table'[rate]) > MAX('UCL Table'[UCL]), "#FF0000",
        MAX('UCL Table'[rate]) < MAX('UCL Table'[LCL]), "#00C853",
        /* else */                                      "#A0A0A0"
    )
    

    enter image description here