Skip to content

AggregateByField

cartographer


cartographer / aggregateByField

aggregateByField(items, groupField, aggregateField, operation): Record<string, number>

Defined in: queries/queryFunctions.ts:29

Apply a numeric aggregation operation to items grouped by a field.

Groups items by groupField, then applies sum/avg/min/max/count to aggregateField values within each group.

CatalogItem[]

Array of items to aggregate

string

Field key to group by

string

Field key containing numeric values to aggregate

Type of aggregation: ‘sum’, ‘avg’, ‘min’, ‘max’, or ‘count’

"sum" | "avg" | "min" | "max" | "count"

Record<string, number>

  • Object mapping group keys to aggregated numeric results
const byAuthor = aggregateByField(items, 'authors', 'word-count', 'sum');
// { 'Lovecraft, H. P.': 150000, 'Smith, Clark Ashton': 85000 }