Question

I'm currently using telerik reports to create bills. For this I take the customer from the database and sum up the cost of all articles he has confirmed.

Thus the textbox field for the cost has the following code inside:

=Sum(IIf(Fields.IsConfirmed>0,Fields.Cost,0))

This shall make sure that I only sum up costs for the customer where he has confirmed that he wants it on the bill.

When I use the sum without the IIf it functions as expected, displaying all the costs summed up (in this case too many costs as also unconfirmed are included). But WITH the IIf included the costs are off:

  1. Not a single decimal digit is displayed
  2. The sum values themselves are slightly off

In total it looks to me as if the IIf leads to the Fields.Cost values being rounded and THEN summed up which is completely unexpected and unwished behaviour.

An alternative would be that I use a view that does these calculations directly in the database instead of doing it in the report, but I would like to have the whole logic in the report if possible.

So the question is: Is there any way to sum these filtered lines up WITHOUT them getting rounded in the process?

On a special note: I can't reduce the number of returned lines through a where statement as I also need the number of total items the customer has including the nonconfirmed one for another textbox on the same report.. Also possibly relevant, the data is stored in the database as decimal(15,2) and I use the entity framework to get the data out of the database (although like I indicated before if I don't use IIf then the rounding problem does not appear and I have decimal digits).

Was it helpful?

Solution

I've found a solution there. The problem is a typical one from other programming languages and still as easy the overlook in each one.

In effect what I'm doing there is adding up a number of floats, but if the field isconfirmed is <= 0 I'm adding an INTEGER value (0). As is in many other such situations (in different programming languages) a conversion happens then. Thus the Integer value in the SUM field leads to the whole sum being seen as INT. Although what is still a bit of a surprise there is that it seems like that even the partial sums get then converted into INT values (at least that is the impression gained from tests).

The solution is now quite easy there and completely fixes this problem:

=Sum(IIf(Fields.IsConfirmed>0,Fields.Cost,0.00))

The 0.00 leads to the zero value being interpreted as a number with decimals and thus no int conversion happens.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top