Groups | Blog | Home
all groups > sql server reporting services > april 2005 >

sql server reporting services : SUM() Function Produces Erroneous Results


Smit-Dog
4/8/2005 9:39:04 AM
It appears that I have come across a very weird but bad bug in the SUM()
function in the Report Designer.

I have a series of financial numbers, broken down into various expense
categories, in a rolling 12 month format. For each month, a value is
retrieved from the dataset and displayed. At the end of the 12 month series,
I'm using a SUM() function to display a grand total for all values in the 12
month series.

Here is the formula used:

=sum(Fields!Sales_M01.Value + Fields!Sales_M02.Value +
Fields!Sales_M03.Value + Fields!Sales_M04.Value + Fields!Sales_M05.Value +
Fields!Sales_M06.Value + Fields!Sales_M07.Value + Fields!Sales_M08.Value +
Fields!Sales_M09.Value + Fields!Sales_M10.Value + Fields!Sales_M11.Value +
Fields!Sales_M12.Value)

The problem is that the SUM() incorrectly sums the series if a zero (0)
value is encountered for any particular month. It continues to incorrectly
sum the series until it hits a record where there are not any zeros. What it
appears to do is sum the 12 month series for any contiguous grouping of
records where there is a zero value for a month, and uses that aggregation
for the SUM() total for each of the records in the grouping.

If a particular month does not have any number to report, the field in the
database contains a 0 value, so nulls are not a factor here.

To clearly show how the SUM() function is screwing up, I've provided a link
to an Excel file that was created by exporting the report. I've changed the
company names for obvious reasons. Check it out here:

http://home.comcast.net/~wcsmith/SSRS_Sum_Error.xls

I have a total column that was calculated by SSRS in the Report Designer
with the SUM() function. Next to that I have a column using the Excel SUM()
function to compare the two methods, and find the errors.

The rows shaded in purple is where the SSRS SUM() function has screwed up.
If you select all the values for all the months in the contiguous range, i.e.
the entire purple sub-section, you will see that this is the total that the
SSRS SUM() function has come up with - for every record in the contiguous
range where a $0 was encountered. Very, very weird, and very bad when
reporting on financial calculations.

I don't think I'm doing anything wrong with the SUM() function. It appears
that when $0 are encountered, SSRS just keeps adding not only for the current
record, but all subsequent records until it finds one where a zero does not
exist in any of the monthly values. This is the only thing I can surmise from
looking at the results.

I am open to suggestions to workaround this issue. Should I be summing the
text boxes instead of the underlying values from the dataset? Should I
include the summed totals in the stored procedure that supplies the dataset,
and reference these directly?

Thanks!

- Bill
Smit-Dog
4/11/2005 11:06:02 AM
So..... Nobody else has experienced this bug in the SUM() function?

Seems to me that I need now do all calculations in SQL, which is unfortunate
since SSRS offers these functions in the designer.

[quoted text, click to view]
Bassist695
4/11/2005 1:35:02 PM
Smit -

In the SQL for your report, do you have an ISNULL function around your
financial amounts? Could it be that you're adding NULLs?

One more observation after looking at your spreadsheet. This "bug" is
affecting the same companies (8-11) almost every time, and down in the
"Special" section, it is obvious that this issue does not arise every time
you have zero-amounts.

You'll also notice that if you sum all purple values in the "Excel Sum()"
column for each section of the report, the value = the repeated value in the
"SSRS SUM() column. It appears that RS is rolling up those companies to the
same level. I would recommend checking your SQL again, and do not think that
this is a Reporting Services bug by any means.




[quoted text, click to view]
Smit-Dog
4/11/2005 3:01:01 PM
Thanks for checking it out Bassist...

There are not any NULLs in the dataset. Everything in the returned dataset
is pure numbers, including zeros (0s) where there was not a value.

Regarding the problem affecting the same companies.... If I add a WHERE
clause to the SQL that returns the dataset to just return the 4 companies in
question, the SUM() function works fine.

What's puzzling is that the SQL is not doing any grouping. The returned
dataset is pretty much in the format as the report layout.

For some reason the SUM() function in the designer is going haywire under
certain circumstances, I just can't seem to figure out what that circumstance
is. It somehow seems to be prevelant with a larger number of companies in the
dataset, and the presence of $0 amounts.

I can't spend much more time on this problem, so may just resort to doing
the SUMing in the SQL.

[quoted text, click to view]
AddThis Social Bookmark Button