Cross series aggregation of the data from multiple series within a measurement

Attempting to answer my own question: I have come up with one solution (untested), however it would be critical to get the correct aggregateWindow period to avoid summing data from the same host twice:

total = (tables=<-) => tables
  |> reduce(
    fn: (r, accumulator) => ({
      index: accumulator.index + 1,
      total: if accumulator.index == 0 then r._value else r._value + accumulator.total
      mean: accumulator.total / (accumulator.index +1)
    }),
    identity: { index: 0, total: 0.0, mean: 0.0 }
  )
  |> drop(columns: ["index"])

// --- Adjust below as necessary ---
from(bucket: "my_database")
  |> range(start: -1h)
  |> filter(fn: (r) => r._measurement == "memory_measurement" and r._field == "ram_free_field")
  |> aggregateWindow(
    every: 1m,
    fn: (tables=<-, column) => tables |> total()
  ) 

This is based on the staff answer in Flux group by time
Can anyone else come up with something better?

Ive included the mean in the custom aggregation function as I feel that multiplying the mean by the number of different host_tags in the data set would at least give a reasonable value to display which would be tolerant of miss aligned data, but I have no idea how to do that.
Really I want all tags available to me in the reduce function.