How would I go about creating the following scenario:

REPORT
group1 header
group2 header
10 A
10 A
08 B
group2 footer
total 20 A
group2 header
05 A
10 A
08 B
group2 footer
total 15 A
group1 footer
total 35 A
REPORT

I've narrowed it down to using DSUM, but a little pseudo-code would help me along.

As my report is running from a query, I'm a little confused over what the 'domain' will be when creating the sums under each group.

thanks.