reporting-servicesreportbuilder3.0

Why isn't this code working in SSRS ReportBuilder?


I can't figure out why this statement is not working in ReportBuilder.

=IIF(Count(Fields!TITCount.Value) > 0, "- Title Documents", Nothing)

In this case, the database has 3 records, all with TITCount of 0. So, when the report runs, the count field should be 0 and nothing should be displayed. It is displaying -Title Documents

Here is the field from the query in the database:

TITCount
0
0
0

Any ideas why this is evaluating to > 0 when the report runs?


Solution

  • Try this..

    =IIF(SUM(Fields!TITCount.Value) > 0, "- Title Documents", Nothing)
    

    Brief explanation


    By using COUNT() you are just counting the number of time TITCount exists within the context of the expression, so in your case it will count 3, regardless of the value.

    As you only want to see if any rows are greater than zero than we can simply sum them.

    If you were doing something a little more complex, such as testing for a specific value for instance then you can then use do a similar thing but with an extra nested level such as

    =IIF(
         SUM( IIF(Fields!myField.Value = 123, 1, 0) ) > 0
         , "Found some values that were exactly 123"
         , "No values were exactly 123"
         )