Search code examples
reporting-servicessql-server-2008-r2sumiif

SUM and IIF statements are not giving results in Text Values


I am creating a report using Report Builder 3.0 SQL Server 2008 R2. One Form there is a check box, when checked it save Yes in view/table and if not checked it save No in view/table. When Checked, I need to print a text statement on report and if not checked then I need to print another field's value. If I use the following expression:

=SUM(IIF(Fields!CheckekBox_Checked.Value="Yes", 1,0) ,"DataSet1")

it prints 1, when checked and print 0 when not checked. Works fine. but when I use the following expression:

=SUM(IIF(Fields!CheckekBox_Checked.Value="Yes", "CHECKBOX is CHECKED", Fields!Address.Value) ,"DataSet1")

It didn't print anything but #Error (as text) on report. There is no error while saving the report. Can you please help me to correct the syntax?


Solution

  • The below code is an example of what you would run to count how many instances of a condition are present. For example, you want to know how many checkboxes are checked? It will return a "1" for every check box that is checked and then add them all together to give you a total count of how many are checked.

    =SUM(IIF(Fields!CheckekBox_Checked.Value="Yes", 1,0) ,"DataSet1")
    

    When you run the below code, you are telling your expression to return the text "CHECKBOX is CHECKED" whenever the expression is true or return the "address" value when it is not. When it is done, you're telling it to add all "CHECKBOX is CHECKED" and address values. What's "CHECKBOX is CHECKED" plus "CHECKBOX is CHECKED"? An error, that's what.

    =SUM(IIF(Fields!CheckekBox_Checked.Value="Yes", "CHECKBOX is CHECKED", Fields!Address.Value) ,"DataSet1")