# Sum aggregration not counting all rows

**URL:** <https://forum.servoy.com/t/sum-aggregration-not-counting-all-rows/4662>\
**Category:** Classic Servoy\
**Created:** [August 27, 2005, 1:39am UTC](https://forum.servoy.com/t/sum-aggregration-not-counting-all-rows/4662 "2005-08-27T01:39:49Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![lee](https://avatars.discourse-cdn.com/v4/letter/l/bc8723/32.png) [@lee](https://forum.servoy.com/u/lee)\
**Post date:** [August 27, 2005, 1:39am UTC](https://forum.servoy.com/t/sum-aggregration-not-counting-all-rows/4662/1 "2005-08-27T01:39:49Z")

</div>

I am having trouble with a sum aggregation. I am performing a sum on a table called orderitems, on a field called linetotal, which is worked out via quantity \* price, a fairly basic thing to do. The problem is that if I add to orderitems via a formindialog, the aggregate function doesn’t seem fire, so I can add items to an order without the total being updated. The aggregation is used in a stored calculation on an orders table, to work out the current total for an order:

```auto
var totaldiscounts = discount + preorders_to_credits_total.orderCreditsTotal;
var totalcharges = deliverycharge + surcharge + vat;
return (preorders_to_preorderitems.agg_sum_orderItemsLineTotals + totalcharges) - totaldiscounts;

```

When I add most items to an order, the total updates. However I have to add pizza toppings via a formindialog to ensure that they are associated with a pizza item and it’s these items that are not counted in the total when they’re added to an order. HOWEVER! If I add say three toppings ($0.50) to a pizza ($1.00) for a total of $2.50, then delete one topping, the total updates showing the new correct total for pizza + two toppings ($2.00).

I am at a loss as to why this is happening, and it is rather a large problem. Any ideas?

---

<div class="post-metadata">

**Author:** ![lee](https://avatars.discourse-cdn.com/v4/letter/l/bc8723/32.png) [@lee](https://forum.servoy.com/u/lee)\
**Post date:** [August 28, 2005, 1:19am UTC](https://forum.servoy.com/t/sum-aggregration-not-counting-all-rows/4662/2 "2005-08-28T01:19:26Z")

</div>

Whoops – forgot version information

Servoy 2.2 final running on linux (ubuntu) using java 1.5.0\_04

Any suggestions?

---

<div class="post-metadata">

**Author:** ![lee](https://avatars.discourse-cdn.com/v4/letter/l/bc8723/32.png) [@lee](https://forum.servoy.com/u/lee)\
**Post date:** [August 29, 2005, 1:19pm UTC](https://forum.servoy.com/t/sum-aggregration-not-counting-all-rows/4662/3 "2005-08-29T13:19:47Z")

</div>

Just tried the latest beta (2.2.1 rc2 is what the announcement says, but 2.2.2 build 328 is what shows up in the Help \> About dialog) and this problem is still present.

---

<div class="post-metadata">

**Author:** ![Karel\_Broer](https://avatars.discourse-cdn.com/v4/letter/k/bcef8e/32.png) [@Karel\_Broer](https://forum.servoy.com/u/Karel_Broer)\
**Post date:** [September 5, 2007, 11:44am UTC](https://forum.servoy.com/t/sum-aggregration-not-counting-all-rows/4662/4 "2007-09-05T11:44:51Z")

</div>

I have same issue here…

I have a stored calc that returns an amount of minutes:

```auto
var vMinutes = null

if(hours_estamated || minutes_estamated) {
	vMinutes = minutes_estamated + hours_estamated * 60
}

return vMinutes

```

When I sum this calculation, the sum doesn’t contain all records…

Servoy Developer  
Version 3.1.6-build 410  
Java version 1.5.0\_07-87 (Mac OS X)

---

<div class="post-metadata">

**Author:** ![IT2Be](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@IT2Be](https://forum.servoy.com/u/IT2Be)\
**Post date:** [September 5, 2007, 12:08pm UTC](https://forum.servoy.com/t/sum-aggregration-not-counting-all-rows/4662/5 "2007-09-05T12:08:57Z")

</div>

```auto
if(hours_estamated || minutes_estamated) { 
   vMinutes = minutes_estamated + hours_estamated * 60 
}

```

I would do this, and that might be the cause as well (unless you prefill with 0):

```auto
var hEstimated = hours_estimated != null ? hours_estimated : 0;
var mEstimated = minutes_estimated != null ? minutes_estimated : 0;

vMinutes = mEstimated + (hEstimated * 60);

```

---

<div class="post-metadata">

**Author:** ![IT2Be](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@IT2Be](https://forum.servoy.com/u/IT2Be)\
**Post date:** [September 5, 2007, 12:11pm UTC](https://forum.servoy.com/t/sum-aggregration-not-counting-all-rows/4662/6 "2007-09-05T12:11:57Z")

</div>

BTW Karel, did you know Riccardo already uses that Avatar?

---

<div class="post-metadata">

**Author:** ![Riccardino](https://avatars.discourse-cdn.com/v4/letter/r/41988e/32.png) [@Riccardino](https://forum.servoy.com/u/Riccardino)\
**Post date:** [September 5, 2007, 2:08pm UTC](https://forum.servoy.com/t/sum-aggregration-not-counting-all-rows/4662/7 "2007-09-05T14:08:06Z")

</div>

> IT2Be:  
> BTW Karel, did you know Riccardo already uses that Avatar?

Hei: it’s not an Avatar. It’s a portrait! ![;)]( "Wink")

---

<div class="post-metadata">

**Author:** ![IT2Be](https://avatars.discourse-cdn.com/v4/letter/i/dc4da7/32.png) [@IT2Be](https://forum.servoy.com/u/IT2Be)\
**Post date:** [September 5, 2007, 2:12pm UTC](https://forum.servoy.com/t/sum-aggregration-not-counting-all-rows/4662/8 "2007-09-05T14:12:57Z")

</div>

hmmm a portrait. Well in that case you are a cute boy ![:lol:]( "Laughing")

---

<div class="post-metadata">

**Author:** ![Harjo](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/harjo/32/4873_2.png) [@Harjo](https://forum.servoy.com/u/Harjo)\
**Post date:** [September 5, 2007, 5:43pm UTC](https://forum.servoy.com/t/sum-aggregration-not-counting-all-rows/4662/9 "2007-09-05T17:43:00Z")

</div>

be carefull with stored calculations and aggregates.  
first you have to had every record in view (on the form), before, the calc is really calculated. (saved to the DB) Only THAN the aggregate will work.

if you want to be 100% sure, you have to do: databasemanager.recalculate(foundset) first!  
(but that can be a real time consuming thing if you have thousands of records in your foundset.)

---

<div class="post-metadata">

**Author:** ![Karel\_Broer](https://avatars.discourse-cdn.com/v4/letter/k/bcef8e/32.png) [@Karel\_Broer](https://forum.servoy.com/u/Karel_Broer)\
**Post date:** [September 5, 2007, 8:56pm UTC](https://forum.servoy.com/t/sum-aggregration-not-counting-all-rows/4662/10 "2007-09-05T20:56:55Z")

</div>

> Riccardino:
> 
> > IT2Be:  
> > BTW Karel, did you know Riccardo already uses that Avatar?
> 
> Hei: it’s not an Avatar. It’s a portrait! ![;)]( "Wink")

Ai! Sorry… no… haven’t noticed..  
Gonna get myself some other funny avatar soon!
