Report Builder 3.0 SWITCH expression DEFAULT/ELSE

50,927

There is no default clause in the SSRS Switch expression.

However, you can always modify your expression slightly:

=Switch 
(
  Parameters!UserFranNr.Value = "99","ID99",
  Parameters!UserFranNr.Value = "87","ID87",
  true, "ID0"
)

Since any time the last condition is hit it will be explicitly evaluated to true, the last row will effectively act as a default value.

I've used this in the past without issues. Other than perhaps generating frowns in people who read the expression, it works perfectly well with minimal effort.

As to whether it's sensible behaviour to have no default clause, well, that's a question for Microsoft. It certainly seems odd to me, but there you go.

Share:
50,927
Admin
Author by

Admin

Updated on July 09, 2022

Comments

  • Admin
    Admin almost 2 years

    I am trying to display a different logo based on the users franchise number.

    Parameter = UserFranNr

    If the value <> 99 and <> 87, then the embedded image to display is ID0. (Embedded image names are strings.)

    This works with nested IIFs but seems to be the right time/place to use SWITCH.

    (There is a strong possibility that more franchises will use their own logo in future.)

    =Switch 
    (
    Parameters!UserFranNr.Value = "99","ID99",
    Parameters!UserFranNr.Value = "87","ID87",
    "ID0"
    )
    

    I have not found any documentation that explains how to implement a default value using SWITCH.

    Is this even possible? If so how? If not any decent alternatives? Thanks

    Resources: Expression Examples (Report Builder and SSRS) Define Formula Dialog Box (Report Builder)

    Plus here and other forums.

  • Admin
    Admin over 10 years
    LOL. Brilliantly simple! Perfect! Thanks Ian :)
  • Liquid Core
    Liquid Core about 7 years
    The real question is what kind of unskilled wit tought it was a good idea to implement switch operator without an explicit DEFAULT case, since it's decades that switch it's working like this flawlessly. Microsoft have always suprirses.
  • SherlockSpreadsheets
    SherlockSpreadsheets over 5 years
    A life saver, you are. (I guess, Yoda I am).