I don't really understand what it is you are trying to do. But have you ever used subsummary parts in your layout?
These can be used to group data and show sub totals etc.
Might be interesting for you.
One thing to keep in mind is that you need to sort the records on the sub summary field(s)
And this works mainly in a list view.
Also: put your summary field in the sub summary part.
Take a look at using the SubSummary function. It accesses the same sub total produced by a sub summary layout part so that you can use that sub total in a calculation. You may need to use a summary field that is not defined as a running total summary field to get the results that you want.