I am trying to display a different logo based on the users franchise number.
Parameter = UserFranNr
If the value <> 99 and <> 87, then the embedded image to display is ID0. (Embedded image names are strings.)
This works with nested IIFs but seems to be the right time/place to use SWITCH
.
(There is a strong possibility that more franchises will use their own logo in future.)
=Switch ( Parameters!UserFranNr.Value = "99","ID99", Parameters!UserFranNr.Value = "87","ID87", "ID0" )
I have not found any documentation that explains how to implement a default value using SWITCH
.
Is this even possible? If so how? If not any decent alternatives? Thanks
Resources: Expression Examples (Report Builder and SSRS) Define Formula Dialog Box (Report Builder)
Plus here and other forums.
As the solution, add the following expression in the last column header. Add the following expression in the "last column value/detail". Now, render the report with the parameter set to "Address" and then "Phone" and then "Email". The output with each parameter selection is as shown below.
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.
The CDate function converts the value to a date. The Now function returns a date value containing the current date and time according to your system. DateDiff returns a Long value specifying the number of time intervals between two Date values.
For example, to store an XML report file in the C:\Temp\Reports directory with the filename stored in a variable FileGlobals. ReportFileName in the current process model, use the expression "C:\\Temp\\Reports\\" + FileGlobals. ReportFileName + ".
There is no default clause in the SSRS Switch
expression.
However, you can always modify your expression slightly:
=Switch ( Parameters!UserFranNr.Value = "99","ID99", Parameters!UserFranNr.Value = "87","ID87", true, "ID0" )
Since any time the last condition is hit it will be explicitly evaluated to true
, the last row will effectively act as a default value.
I've used this in the past without issues. Other than perhaps generating frowns in people who read the expression, it works perfectly well with minimal effort.
As to whether it's sensible behaviour to have no default clause, well, that's a question for Microsoft. It certainly seems odd to me, but there you go.
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