Basic idea: Add additional rows to a filtered repeating table showing subtotals.
Example:
Data Source: Vendor, Month, ServiceType, InvoiceAmount
The user selects a Vendor from a drop down list then the repeating table shows all the InvoiceAmounts for that Vendor, organized by month and type. (I can already get that far.) But also, rows should be added, interleaved at the appropriate places, that show the subtotals of InvoiceAmounts by Month and ServiceType. Obviously, this scenario requires sorting, but assume the data is pre-sorted. And assume another column to hold the "Total" label.
I cannot use C# or managed code. It needs to work for offline forms on machines that don't have .NET. I have done this 1.3 million times in VB, but InfoPath has me stumped. However, maybe my programming background is keeping me from seeing the solution.