0

I´m stuck on a color expression using a switch command.

I want to be able to set the color green if the following is true.

=Switch( Fields!direction.Value = "North" and (Fields!transport.Value = "Car" and Fields!units.Value >= 1) and (Fields!transport.Value = "Bike" and Fields!units.Value >= 2), "Green", 
        1=1, "Red"
)

Is it possible to use that many "and" in a switch statement? Is there a better way to write this code, maybe to include a iif statement?

Kiwie
  • 1
  • 1

1 Answers1

0

You need to explain the conditions and the desired results to get a real answer but this might help you understand where the problem is..

Assuming you want to test if

1. Direction is north
2.a. transport is car and units is >= 1
2.a. transport is bike and units is >= 2
and then return "Green", other wise return "Red"

Then the change is quite simple

=Switch( 
        Fields!direction.Value = "North" 
            and (
                    (Fields!transport.Value = "Car" and Fields!units.Value >= 1) 
                    OR
                    (Fields!transport.Value = "Bike" and Fields!units.Value >= 2)
            ), "Green", 
        True, "Red"
)

All I did here was to make the transport/units check a single test with two conditions, if either (OR) is true then that part is True I Also replace the 1=1 with True but 1=1 will work the same, they both return True

Alan Schofield
  • 19,839
  • 3
  • 22
  • 35
  • Hi Alan, thanks for your answer. My challenge here is that they all need to be true. So the directions needs to be North and transport with car needs to be >= 1 and transport with bike needs to be >= 2 then it should return green. Otherwise it should return red. – Kiwie Apr 13 '22 at 15:00
  • That's what the expression in my answer does. They cannot all be true all the time as transport, for example, can only be one value on each record, it cannot be both. If this does not help, **edit** your question and given some sample data with expected results. – Alan Schofield Apr 13 '22 at 15:19