Using AND in Switch Expression in SSRS 2008

Etienne picture Etienne · Oct 1, 2012 · Viewed 16.8k times · Source

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.

Answer

Davos picture Davos · Oct 4, 2012

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