Reputation: 39
I am trying to give the below expression for font color in ssrs:
=IIF(Fields!A.Value<>0 AND Fields!P.Value <>0, IIF(Fields!A.Value >= Fields!P.Value, "Green", "Red"), "Black")
It works fine for all the numbers except when Either of A or P is 0 I am getting both A and P as Black.
Basically, All I want is:
The IIF syntax did not work as I expected i.e. When I have 0 in P and 5 in A then the font color should be green and the vice versa should be red.
I have to work a way around to get what I want with Switch statement.
=Switch(Fields!A.Value>=Fields!P.Value and (Fields!P.Value<>0 AND Fields!P.Value <>0), "Green",
(Fields!A.Value = 0 and Fields!P.Value =0), "Black",
(Fields!A.Value=0 AND Fields!A.Value < Fields!P.Value), "Red",
(Fields!P.Value = 0 AND Fields!A.Value > Fields!P.Value), "Green")
Can someone explain to me why my IIF statement did not work please?
Your help is much appreciated. Thank you.
Upvotes: 1
Views: 20550
Reputation: 3028
If your question is
My values are P = 0, A = 5, but colour is not green
(which I think it is)
Then this is because you are using the construct
=IIF(Fields!A.Value<>0 AND Fields!P.Value <>0 , truepart, falsepart)
You are saying that only do the true part when A is not zero AND P is not zero. Because you are comparing the values 0 and 5, then because one of these is zero, the false part will execute instead.
To implement the rules
- When A = P = 0 Black
- When A >= P (for eg. say both are 5) then Green
- When A < P Red
Then you will need an expression like
=iif(Fields!A.Value = 0 AND Fields!P.Value = 0, "Black", <-- Set to Black if both zero
iif(Fields!A.Value >= Fields!P.Value , "Green", <-- Else, set to Green if A >= P
"Red")) <-- Otherwise set to Red
Hopefully this is helpful. If I have misunderstood please let me know and I shall try to assist further
Upvotes: 3
Reputation: 5243
Your IIF
is not working because it is doing something else. To understand what it's doing, the equivalent SWITCH
for that IIF
is:
=Switch(Fields!A.Value>=Fields!P.Value and (Fields!P.Value<>0 AND Fields!P.Value <>0), "Green",
NOT(Fields!A.Value>=Fields!P.Value and (Fields!P.Value<>0 AND Fields!P.Value <>0)), "Black",
Fields!A.Value<>0 AND Fields!P.Value <>0 AND NOT(Fields!A.Value >= Fields!P.Value), "Red"
What you actually needed was:
IIF(
Fields!P.Value=0 AND Fields!P.Value =0,
"Black",
IIF(
Fields!A.Value>=Fields!P.Value,
"Green",
"Red"
)
)
Upvotes: 0