Skip to main content

Group

Calculates measures on input records, with optional groupings:

Example without groups
// this stage returns a single row with one column per measure
{
measures: {
"avg_sales": "avg(sales)",
"total_sales": "sum(sales)"
}
}

Optionally, groupBy may contain a list of expressions by which to group the calculations. This is useful for comparing results of mutually exclusive groupings. For overlapping groupings, use the Aggregate stage instead.

Example with groups
// this stage returns a row for every discovered combination of region and metro
// it returns four columns: region, metric, avg_sales, and total_sales
{
groupBy: ["region", "metro"],
measures: {
"avg_sales": "avg(sales)",
"total_sales": "sum(sales)"
}
}

Each GroupBy entry can be an object, to include additional field meta. Measures too can be objects.

Example with Field Meta
// this calcultes the same as above, but returns additional Field Meta to help a visualizer
{
groupBy: [
{ syntax: "region", label: "US Region" },
{ syntax: "metro", label: "Metropolitan Area" }
],
measures: [
{ syntax: "avg(sales)", label: "Average sales", format: "$.2f" },
{ syntax: "sum(sales)", label: "Total sales", format: "$.2f" }
]
}