Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I write an if else statement in Reporting Services expression language?

I would like to write a Reporting Services "Expression" that basically behaves as the following (pseudo code)...

if ([Fields!StateProvinceId.Value] == 1)
{
   return "Ontario";
}
else if ([Fields!StateProvinceId.Value] == 2)
{
   return "Quebec";
}
else if ([Fields!StateProvinceId.Value] == 3)
{
   return "Manitoba";
}
// ...
// more cases same pattern

I don't see this type of logic do I have to nest a bunch of IIF?

=IIF(Fields!StateProvinceId.Value = 1, "Ontario", IIF(Fields!StateProvinceId.Value = 2, "Quebec", IFF(Fields!StateProvinceId.Value = 3, "Manitoba", "Unknown Province")))
like image 530
Justin Avatar asked Aug 23 '10 21:08

Justin


People also ask

How do you write an if else expression in SSRS?

location. Value = “CA”, “Bold”, “Italic”) SSRS iif statement The format of the IIF() statement is as follows: =IIF(Expression, Condition set when the expression is true, Condition set when the expression is false) It should be a Boolean expression, according to parameter 1.

How do I use IIF in SSRS expression?

Using IIF Function in SSRS We are going to add a new field to the report data set to determine if the Order Year is the Max or Current Year. As shown below, the dataset properties window is opened, and the Fields tab is selected. After clicking Add, at the bottom of the list a new field is added.

What language is used in SSRS expressions?

Also, the expression language used in SSRS is Visual Basic.


1 Answers

Have you tried a switch statement?

= Switch( Fields!StateProvinceId.value=1,"Ontario", Fields!StateProvinceId.value=2,"Quebec", Fields!StateProvinceId.value=3,"Manitoba")

See "decision functions" on this page for example:

http://msdn.microsoft.com/en-us/library/ms157328.aspx

like image 86
Anon246 Avatar answered Sep 25 '22 11:09

Anon246