Hi,
Did you try list builder to do what you want?
Look at template::list api documentation in your install or
https://openacs.org/api-doc/proc-view?proc=template%3a%3alist%3a%3aelement%3a%3acreate
listbuilder has available properties as "aggregate". As api-browser says:
"Aggregate function to use on this column. Can be 'sum', 'average', or 'count'. The aggregate will be displayed at the bottom of the table. If groupby is used, aggregates for each group will also be displayed."
I already used this template system feature to produce aggregates for exporting as cvs format (also suported as property by listbuilder)
Hope it help you.
/Orzenil