Function aggregateRowGroups

  • Computes the aggregates of all groups (RowGroupIf.results) and their row counts (RowGroupIf.count). A group of the last level aggregates its rows; every group above merges the states of its sub-groups – an average stays the average of all rows (sum and count are merged), never the average of averages.

    Type Parameters

    • T = any

    Parameters

    • groups: RowGroup<T>[]

      the top-level groups of groupRows

    • aggregations: AggregateSpecMap<T>

      key → aggregator ({ umsatz: "sum" }, see AggregateSpecMap)

    • Optional accept: ((sourceIndex) => boolean)

      a filter: only rows it accepts count (index into the source rows)

        • (sourceIndex): boolean
        • Parameters

          • sourceIndex: number

          Returns boolean

    Returns Record<string, unknown>

    the totals over all groups

    Example

    const groups = groupRows(sales, ["region", "produkt"]);
    const totals = aggregateRowGroups(groups, { umsatz: "avg" });
    groups[0].results.umsatz; // 90 – Nord: (100 + 50 + 120) / 3, not the mean of A (110) and B (50)
    totals.umsatz; // 75

    Since

    1.1.94