Search code examples
visual-studio-2010visual-studio-2012reporting-servicesssrs-2008ssrs-2012

Using IIF in SSRS


I'm trying to calculate % value for each group (logic being 'Group A Calls / Total Calls').

The problem is that for some groups I need to use (MAX(Fields!OverallCalls.Value) whereas for other ones I need to use (MAX(Fields!TotalCalls.Value). For this reason, I've added an additional IIF statement at the very bottom, however, for some reason I get an error saying: 'Too many arguments to Public Functions IsNothing(Expression As Object) As Boolean'.

=FORMATPERCENT(
       Sum(
IIF(Fields!Group.Value = "Dissatisfactions Total",
       Fields!TotalDissatisfactions.Value,
IIF(Fields!Group.Value = "RID Total",
       Fields!TotalRidDissatisfactions.Value,
       IIF(
              Fields!Group.Value = "CRT" OR
              Fields!Group.Value = "Escalations"
              ,Fields!ComplaintID.Value
              ,IIF(
                           Fields!Group.Value = "Calls"
                           ,Fields!Calls.Value
                           ,0
                     )
       )
       )
       )  
       ) / IIF(IsNothing(MAX(Fields!OverallCalls.Value), (MAX(Fields!TotalCalls.Value), (MAX(Fields!OverallCalls.Value)
       )

Solution

  • There are errors with missing parenthesis.

    Try the following code

    =FORMATPERCENT(
    Sum(
        IIF(Fields!Group.Value = "Dissatisfactions Total",
            Fields!TotalDissatisfactions.Value,
            IIF(Fields!Group.Value = "RID Total",
                Fields!TotalRidDissatisfactions.Value,
                IIF(
                Fields!Group.Value = "CRT" OR Fields!Group.Value = "Escalations",
                    Fields!ComplaintID.Value,
                    IIF(
                        Fields!Group.Value = "Calls",
                        Fields!Calls.Value,
                        0
                        )
                    )
                )
            )  
       ) 
       / 
       IIF(IsNothing(MAX(Fields!OverallCalls.Value)),  
            MAX(Fields!TotalCalls.Value),  
            MAX(Fields!OverallCalls.Value) 
        )
       )
    

    Also for better readability when you have many nested Iif statements I would advice using switch like the following code

    =FORMATPERCENT(
    Sum(
        Switch (
            Fields!Group.Value = "Dissatisfactions Total", Fields!TotalDissatisfactions.Value,
            Fields!Group.Value = "RID Total", Fields!TotalRidDissatisfactions.Value,
            Fields!Group.Value = "CRT" OR Fields!Group.Value = "Escalations", Fields!ComplaintID.Value,
            Fields!Group.Value = "Calls", Fields!Calls.Value,
            True, 0
            )
    
       / 
       IIF(IsNothing(MAX(Fields!OverallCalls.Value)),  
            MAX(Fields!TotalCalls.Value),  
            MAX(Fields!OverallCalls.Value) 
        )
       )