简体   繁体   中英

Switch expression in SSRS

I wanted to fill cell based on value. First expression works only for LimeGreen, but IIF for all cases. Why?

=Switch(
Code.Trend(Variables!Sold1.Value, Variables!Sold2.Value) > 0, "LimeGreen",
Code.Trend(Variables!Sold1.Value, Variables!Sold2.Value) <= 0 &
Code.Trend(Variables!Sold1.Value, Variables!Sold2.Value) >= -0.05, "Yellow",
Code.Trend(Variables!Sold1.Value, Variables!Sold2.Value) < -0.05, "Red")

=IIF(
Code.Trend(Variables!Sold1.Value, Variables!Sold2.Value) > 0, "LimeGreen",
    IIF(Code.Trend(Variables!Sold1.Value, Variables!Sold2.Value) < 0.05, "Red", "Yellow")
)
=Switch(
Code.Trend(Variables!Sold1.Value, Variables!Sold2.Value) > 0, "LimeGreen",
Code.Trend(Variables!Sold1.Value, Variables!Sold2.Value) >= -0.05, "Yellow",
True, "Red")

Anything above 0 will be LimeGreen. After that, anything above -.05 will be Yellow. Everything else will be Red.

Since the first test looks for >0, the remainining options are all <= 0. This effectively means the second test is all values between -.05 and 0. The final test is the catch all but will only be chosen for values <-.05.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM