I have a report and a subreport that basically prints this:
Here is the code for the main report:
You can specify a calculation type (like sum) when returning values from subreports. Therefore if you want to sum returned values for each group, you'll have to do something like this:
...