refactor(Aggregation): Use local function

The function was always iterating all rows and saving the results on a local variable to be used in only 4/6 of the time, causing a lot of overhead.

Its now wrapped in a local function and is called only when needed.