Etienne
Etienne

Reputation: 7201

Using AND in Switch Expression in SSRS 2008

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.

Upvotes: 3

Views: 17840

Answers (2)

Davos
Davos

Reputation: 5435

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

Upvotes: 5

lc.
lc.

Reputation: 116528

Nest two IIfs:

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

Upvotes: 4

Related Questions