score:16

Accepted answer

You need to use the group.reduce(add, remove, initial) method, like:

var col1DimTotal = col1Dim.group().reduce(reduceAdd, reduceRemove, reduceInitial);

function reduceAdd(p, v) {
  ++p.count;
  p.total += v.value;
  return p;
}

function reduceRemove(p, v) {
  --p.count;
  p.total -= v.value;
  return p;
}

function reduceInitial() {
  return {count: 0, total: 0};
}

Because you're using dc.js, you'll need to use chart.valueAccessor method to use the average in your charts, like:

chart.valueAccessor(function(p) { return p.value.count > 0 ? p.value.total / p.value.count : 0; });

Related Query

More Query from same tag