t-sqlexpressionssrs-2008-r2negative-number

SSRS 2008R2 - Calculation in row group expression not working due to aggregation of varying data types - is this due to negative values?


The expression in the 'Net Effect' row in the second table is giving #Error as the result(the expression is using aggregate function on data of varying data types). The same expression works in the other tables but this table does have negative values where the count type = "Renewed Member" in the matrix. Is that what is causing the issue? Would negative values be classed as a different data type?

Report Layout

In my sql query I have converted the NULL values to 0.00 using this:

SELECT COUNT(x.ccx_membershipid) as CountAll
                , x.FinancialYear
                , x.Month3Char
                , x.MonthSort
                , SUM(ISNULL(x.ccx_membershipfee,0.00)) AS FeeTotal
                , x.CountType

FROM #Merged X

My Expression is:

=SUM(IIf(Fields!CountType.Value="New Member",Fields!FeeTotal.Value,0.00))
+
Sum(IIF(Fields!CountType.Value="Win-back",Fields!FeeTotal.Value,0.00))
+
Sum(IIF(Fields!CountType.Value="Renewed Member",Fields!FeeTotal.Value,0.00))
-
Sum(IIF(Fields!CountType.Value="Inactive Companies",Fields!FeeTotal.Value,0.00))
-
Sum(IIF(Fields!CountType.Value="Lapsed Member",Fields!FeeTotal.Value,0.00))
-
Sum(IIF(Fields!CountType.Value="Resigned/Cancelled Member",Fields!FeeTotal.Value,0.00))

There are no text values that I can see. If it is indeed the negative values that are causing the issue how do I get around that? Thank you in advance for any advice that you can give.


Solution

  • Thanks to this post: SSRS 2008r2 Using Aggregate on field with an Expression
    Adding Cdec around my expression AFTER the SUM has made it work.

    =SUM(Cdec(IIf(Fields!CountType.Value="New Member",Fields!FeeTotal.Value,0.00)))
    +
    Sum(Cdec(IIF(Fields!CountType.Value="Win-back",Fields!FeeTotal.Value,0.00)))
    +
    Sum(Cdec(IIF(Fields!CountType.Value="Renewed Member",Fields!FeeTotal.Value,0.00)))
    -
    Sum(Cdec(IIF(Fields!CountType.Value="Inactive Companies",Fields!FeeTotal.Value,0.00)))
    -
    Sum(Cdec(IIF(Fields!CountType.Value="Lapsed Member",Fields!FeeTotal.Value,0.00)))
    -
    Sum(Cdec(IIF(Fields!CountType.Value="Resigned/Cancelled Member",Fields!FeeTotal.Value,0.00)