group_by_aggregate
Group records by a field and aggregate another field per group using sum, avg, min, max, or count. Returns sorted results with optional limit for quick subtotals.
Instructions
Group records by a field and aggregate another field per group. Like a SQL GROUP BY or Excel pivot. Returns sorted results with optional limit. Use for subtotals by supplier, business unit, status, etc.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Max number of groups to return (e.g. top 10). | |
| records | Yes | Array of record objects. | |
| sort_by | No | Sort order (default: value_desc = highest first). | value_desc |
| agg_field | Yes | Field to aggregate within each group. | |
| operation | No | Aggregation operation (default: sum). | sum |
| group_field | Yes | Field to group by (e.g. 'SupplierName', 'BusinessUnit'). | |
| decimal_places | No |