I couldn't get this expression working with reporting services. I have to use IF and ELSE IF statement. Thank you for any suggestions.
= Switch( IsNothing(Fields!field_date.Value),"", Fields!set_flag.Value=1,"Declined", Fields!field_name.Value)
Here is what I am trying to do.
If(IsNothing(Fields!field_date.Value)) Then "";
ElseIf Fields!set_flag.Value=1 Then "Declined";
Else Fields!field_name.Value
Using SWITCH Function in SSRSThe switch function allows multiple expressions as used in the 2nd line of the statement that contains "and". Similarly, or, orelse, and andalso could be used in this context. The 1=1 at the end is the "catch all" if none of the expression fit into the logical values.
In Design view, click the text box on the design surface to which you want to add an expression. For a simple expression, type the display text for the expression in the text box. For example, for the dataset field Sales, type [Sales] . For a complex expression, right-click the text box, and select Expression.
Expressions are written in Microsoft Visual Basic, and can use built-in functions, custom code, report and group variables, and user-defined variables.
Doesn't SSRS use the VB Runtime Library? In which case, the switch statement is documented here and states that you must have an even number of elements passed in. If this is your issue, you're probably getting an ArgumentException
thrown.
If you want to have a default return value, you'd have to add a dummy condition that always evaluates to true:
= Switch( IsNothing(Fields!field_date.Value),"", Fields!set_flag.Value=1,"Declined", True, Fields!field_name.Value)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With