3
votes

I'm trying to write a field expression for a Cell in my report where I have to change the string color of the cell depending on the string value in the cell.

Ex: if the column name as 'result' has a value 'FAIL'in it, the cell should show a Red color.

I tried the following:

=IIF(Fields!result.Value ="fail","red","green")

But It shows all fields in green color. please help

enter image description here

Thanks

1
Your iif statement works fine for me. The string comparison is case sensitive though. Can you confirm that your data in the result field and the string in your iif statement are both lower case?mmarie

1 Answers

3
votes

Try adding a TRIM around your field:

=IIF(Trim(Fields!result.Value)="fail","red","green")

I often run into the same problem when trying to compare text values to literals due to value(s) in the database that were entered with leading or trailing whitespace. TRIM will remove both leading and trailing spaces, or you can use LTRIM for leading spaces only or RTRIM for trailing spaces only.