Print Page | Close Window

Sum field shows count instead of summary

Printed From: Crystal Reports Book
Category: Crystal Reports for Visual Studio 2005 and Newer
Forum Name: Report Design
Forum Discription: The best way to design a report and problems you have encountered
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=6067
Printed Date: 06 May 2024 at 4:51am


Topic: Sum field shows count instead of summary
Posted By: stanleykapo
Subject: Sum field shows count instead of summary
Date Posted: 13 Apr 2009 at 11:06pm
Hi, I haven't found this anywhere so I post it here.

I am using CR with Visual Sutdio 2008 and I have encountered the following problem:

To make it easier to inderstand let's suppose I want to have six collumns in my report - customer, amount(of certain goods), name of the good, place(customer wants the good), the price for one unit of the good, total price.
I want report to group the rows by 'customer', and for each 'customer' count the sum of 'amount' and 'price'.
I designed the report using the wizard, source for the report is '.NET Object'(members of a class). When I look at the 'Main Report Preview' in VS2008 everything works fine.
The problem comes when I create a windows form with crystal report viewer and load it with data. The code creates a new instance of the report, sets its data source to an ArrayList, and then set the report source for the report viewer to this instance.
I have done this many time and it always worked. But in this special case, the two summary fields('amount' and 'price' just don't work. They show count instead of sum.

I have no idea what to do, to me everything seems to be set allright, report shows correct data, just the summary fields don't work. Please help, I am desperate.



Replies:
Posted By: lockwelle
Date Posted: 14 Apr 2009 at 6:32am
First thought is the fields are being interpretted as strings by Crystal...and you can't sum a string. 
 
If this is the case, it's just not pretty, but you can sum the values by hand with formulas.  Hopefully it is possible to change the array designator to numeric for those fields ( I have seen this when working with sample XML files where everything is a string)


Posted By: stanleykapo
Date Posted: 14 Apr 2009 at 8:51am
Unfortunately this is not the case - in the source class they are declared as double.
I also believe that if it was the case you describe, it also would not work in the 'Main Report Preview' in VS.
Thank you anyway, lockwelle.


Posted By: lockwelle
Date Posted: 15 Apr 2009 at 6:30am
I don't use the arrayList object, but in looking at msdn documentation, it states that "when reading the value from an ArrayList you need to explicitly cast it to the data type ".  sounds like it is stored as a string in the array and then cast to the appropriate datatype.  Crystal doesn't know to cast.
 
do any of your number fields sum in aggregate functions in crystal?
 
just wondering.


Posted By: stanleykapo
Date Posted: 15 Apr 2009 at 9:43pm
Yes, I did it analogically with other reports and it works fine.
It also works in 'Main Report Preview' so I believe that when you have objects stored in an ArrayList, Crystal is able to decide about types.
I got an idea that this might not be problem of the sum fuction but something else, as the report in crystalViewer also does not show proper formatting of DateTime item(it shows default instead of what I chose).
And that is a real mystery.



Print Page | Close Window