Search code examples
vbareporting-servicesssrs-2012

SSRS - how to use 3 if statements, one of which is a blank value


I have a report in which one of the columns returns a DB field which can be 1 of 3 possible outcomes - 1, 0 or blank/"". From what I can see, I think the problem here is that the field is blank rather than a NULL value, so any expressions I use seem to result in a #Error. So far I have managed two different expressions which yield two halves of the results I need:

=IIF(Fields!Field1.Value = 1, "Yes", IIF ({Fields!Field1.Value = 0}, "No", "Unanswered"))

The above gets me 1 = "Yes", 2 = "No" and "" = #Error.

=IIF(Fields!Field1.Value="","Unanswered",Fields!Field1.Value)

This second one gets me 1 = 1, 0 = 0 and "" = "Unanswered".

Is there a way I can combine these and have the results appearing as 1 = "Yes", 0 = "No" and "" = "Unanswered"?

Any advice is appreciated!


Solution

  • Try using this SWITCH expression.

    =SWITCH (
            Fields!Field1.Value = 1, "Yes",
            Fields!Field1.Value = 0, "No",
            True, "Unanswered"
        )
    

    The final True acts like and else.

    If this does not work, you may need to cast the field to text and check as follows

    e.g. CStr(Fields!Field1.Value) = "1", "Yes",