Dataset - merge and sum equal cells

I have a template repeater that is configured to work as a Queue planner.

I do a SQL query against a database that returns a dataset to the template instance. These datasets contain “productName” and “consumption” values where “consumption” is calculated by the “lenght” input.

I now need a way to make a Dataset that contains all the datasets returned from the template repeater.
Where i need to SUM the consumption where the “productName” are equal, and add the ones that only have one occurance.

Any good tips for this one?

Before I would even attempt to gather data from internal templates on a repeater, couldn’t you just do a separate query outside of the repeater that summarizes the data you want? If you have the templates set to save to the database on change, then you can have summary fields that update and reflect the values you want.