I am trying to calculate a SUM in an MS Access report the following way:
-
Group1header – label
- Group2header – value
- Detail – example
- Detail – example
- Group2header – value
- Detail – example
- Group2header – value
-
Group1footer [sum of Group2header value]
Somehow, when more detail rows appear, the sum in group1footer is incorrectly calculated (adds value for each detail).
I can not calculate the sums in the query, because the ‘value’ is already a calculated in the query (a subquery would return to many rows):
( ( (sl_ticketdetail.weight,0) * sl_ticketdetail.amount - ( SELECT SUM(sl_invoicedetail.amount) FROM sl_invoicedetail WHERE ticketdetailid = sl_ticketdetail.ticketdetailid ) / 1000 ) * sl_ticketdetail.cost ) / 1000
Any idea on what could be going wrong?
Since you already have the Group2 sums pre-calculated in your query they will be repeated for each row of results and therefore cannot be used (as you found out) to calculate the Group 1 totals.
You have two solutions
1) pre-calculate the Group1 totals in your query as well and simply report them liek you do the Group2 totals
2) use code in the Group2 footer format/print events to capture the value and manually increment a running Group1 total
I would say 1) is the easiest – 2) is a little hairy and sometimes results in inaccurate totals if the users pages back and forth