Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSRS Expressions with If statement

I was doing reporting on SSRS reports. I need to write an expression for the Textbox to show different input parameters if provided. I have tried writting the expression. But couldn't make it perfect. Here I provided sample code in which i need to have a SSRS expression. Anyone help me provide the same expression in SSRS format.

Code

If(Parameters!FromCreationdate.Value !=null && Parameters!ToCreationdate.Value !=null)
{
  "Created Date:"+ Parameters!FromCreationdate.Value + "To Created Date:"+Parameters!ToCreationdate.Value;
}
else if(Parameters!FromCreationdate.Value !=null)
{
  "Created Date:"+ Parameters!FromCreationdate.Value;
}
else if(Parameters!ToCreationdate.Value !=null)
{
 "To Created Date:"+ Parameters!ToCreationdate.Value;
}

Expression

=IIf(isnothing(Parameters!FromCreationdate.Value),"", "From Creation Date:"+Parameters!FromCreationdate.Value, iif(isnothing(Parameters!FromCreationdate.Value)),"", "To Creation Date:"+Parameters!FromCreationdate.Value)

Thanks

like image 313
UniqueChar Avatar asked Nov 18 '25 18:11

UniqueChar


2 Answers

Have a look at Expression Examples (Report Builder and SSRS) and more specifically at SWITCH

The Switch function is useful when you have three or more conditions to test. The Switch function returns the value associated with the first expression in a series that evaluates to true

So you would use it something like

=SWITCH(
TEST_CONDITION_1,VALUE_1,
TEST_CONDITION_2,VALUE_2,
TEST_CONDITION_3,VALUE_3,
....
TEST_CONDITION_N,VALUE_N
)
like image 87
Adriaan Stander Avatar answered Nov 21 '25 07:11

Adriaan Stander


Using SWITCH is a better method, but if you still need/want to nest your IIF statements for some reason, it would be like this instead:

=IIF(Not IsNothing(Parameters!FromCreationdate.Value) And Not IsNothing(Parameters!   ToCreationdate.Value),
    "Created Date: " + Parameters!FromCreationdate.Value +
    " To Created Date: " + Parameters!ToCreationdate.Value,
    IIF( Not IsNothing(Parameters!FromCreationdate.Value),
        "Created Date: " + Parameters!FromCreationdate.Value,
        IIF( Not IsNothing(Parameters!ToCreationdate.Value),
            "To Created Date: " + Parameters!ToCreationdate.Value,
            ""
            )
        )
    )

Alternatively, you could also do this:

=IIF( Not IsNothing( Parameters!FromCreationdate.Value ),
    "Created Date: " + Parameters!FromCreationdate.Value,
    "" ) +
IIF( Not IsNothing( Parameters!FromCreationdate.Value ) AND
    Not IsNothing ( Parameters!ToCreationdate.Value ),
    " ", "" ) +
IIF( Not IsNothing( Parameters!ToCreationdate.Value ),
    "To Created Date: " + Parameters!ToCreationdate.Value,
    "" )

You may need to change the empty string ("") to Nothing if you are creating reports in SSRS 2005 and deploying to 2008. Doing this either with certain export formats (or possibly it was certain browsers) has caused the empty string to look like a dash when we had Bold set on the text field.

like image 37
Christine Penza Avatar answered Nov 21 '25 08:11

Christine Penza



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!