Search code examples
reporting-servicesssrs-2008ssrs-2012ssrs-2008-r2ssrs-tablix

How to write IFF condition in SSRS?


I'm facing an error in SSRS while trying to work on the SSRS IIF condition below. I want to show a responsible person's name on the screen based on the country. Kindly look into below expression:

=IIF(First(Fields!DCPlayer.Value, "dsHeader") like "India" 
     OR First(Fields!DCPlayer.Value, "dsHeader") like "USA" 
     OR First(Fields!DCPlayer.Value, "dsHeader") like "Russia", 
     "Mike will handle this.", 
         IIF First(Fields!DCPlayer.Value, "dsHeader") like "UK", 
         "Hariom will handle this.", 
             IIF First(Fields!DCPlayer.Value, "dsHeader") like "France",
             "Pintu will handle this.", 
                 IIF First(Fields!DCPlayer.Value, "dsHeader") like "China" 
                 OR First(Fields!DCPlayer.Value, "dsHeader") like "Germany", 
                 "Sohan will handle this.", "Sohan will handle this."))

Error: The Value expression for the textrun ‘Textbox66.Paragraphs[7].TextRuns1’ contains an error: [BC30455] Argument not specified for parameter 'Expression' of 'Public Function IIf(Expression As Boolean, TruePart As Object, FalsePart As Object) As Object'.

Picture


Solution

  • This expression appears to be the ideal use for the SSRS SWITCH statement. With a SWITCH, you can list as many expressions to evaluate as you want and you simply pair them with a value to use when that expression is true.

    =SWITCH([Expression to evaluate], [Value], [Expression2], [Value2]....
    

    For your expression, you should rewrite it like the following:

    =SWITCH(First(Fields!DCPlayer.Value, "dsHeader") like "India"  OR First(Fields!DCPlayer.Value, "dsHeader") like "USA" 
     OR First(Fields!DCPlayer.Value, "dsHeader") like "Russia", "Mike will handle this.", 
     First(Fields!DCPlayer.Value, "dsHeader") like "UK",  "Hariom will handle this.", 
     First(Fields!DCPlayer.Value, "dsHeader") like "France", "Pintu will handle this.", 
     True, "Sohan will handle this.")