Crystal Reports: error in sum in formula field
Introduction: I have a very complex report. To make it a little easier, I create my report this way: In VS.net, I have a class. In the report, I created a "File Definitions Only" -file (ttx) that matches the class exactly. In the code behind, I have set the class as the data source of the (sub) report.
Problem: One class (and also a ttx file) has the following fields: PriceTraditional, PriceCommercial. And there are 2 formulas which are SumPriceTraditional, SumPriceCommercial.
When the class is empty, the data source is also empty. This is when the error occurs. Probably because I am taking the sum of a field that is NULL.
The solutions I've tried (but don't work):
- I tried to change PriceTraditional with formulaField (ex: PriceTraditionalDummy, with formula: if isnull ({DamageForReport.PriceTraditional}) then 0 else {DamageForReport.PriceTraditional}. But then I get an error: A number is required here. (Which is caused by another part of the structure.
- I have tried toggling the replacement of defaults on and off (no result)
Question: I just want to have a report where I can use this Sum-FormulaField without blowing up the report if the field used in the sum is empty.
Any advice on how to fix this would be great !!
Respectfully,
Wim
Some things you can try are either resetting 0 as currency using CCur, or overlaying {DamageForReport.PriceTraditional} on a number using CDbl or ToNumber.
It looks like for some reason it thinks that the 0 in the first part and {DamageForReport.PriceTraditional} in the second part are of different types, so you can cast them to match each other.
I haven't tried any of them, but it can be as simple as using $ 0 or 0.0 instead of 0.
Just throw away some ideas. Hope it helps.
source to share
Just follow the steps in this
after
http://crystalrepterrinfo.blogspot.com/2009/11/error-on-sum-in-formula-field-crystal.html
source to share