Using AND in Switch Expression in SSRS 2008

17,029

Solution 1

Nest two IIfs:

=IIf(Fields!DistanceFromOutlet.Value > 500, "Red", IIf(Fields!DistanceFromOutlet.Value < 250, "White", "Orange"))

Solution 2

The Switch function is evaluated from left to right so you can do this:

=Switch(Fields!DistanceFromOutlet.Value <=250, "White", Fields!DistanceFromOutlet.Value <= 500, "Orange", Fields!DistanceFromOutlet.Value > 500, "Red")

What I suspect is that you tried to do this which does not work:

Fields!DistanceFromOutlet.Value > 250 and < 500

That would work if you changed it to be explicit:

Fields!DistanceFromOutlet.Value > 250 and Fields!DistanceFromOutlet.Value < 500
Share:
17,029
Etienne
Author by

Etienne

Updated on June 05, 2022

Comments

  • Etienne
    Etienne almost 2 years

    Below is my code I use in the Color Expression in SSRS 2008 to change the color of the text.

    =Switch(Fields!DistanceFromOutlet.Value > 500, "Red",
    Fields!DistanceFromOutlet.Value < 250, "White")
    

    How would I say if the DistanceFromOutlet.Value > 250 and < 500 it must be Orange?

    So Red text for more than 500.

    Orange text for betweeen 250 and 500.

    And White text for less than 250.