# AggFunc

> _Since v0.1.1_

Built-in aggregation functions for pivot value fields.

Each function is applied per-cell to aggregate the matching data rows into a single value:

| Function | Result | Blank handling |
|----------|--------|----------------|
| `'sum'` | Numeric total of all values | Non-numeric values ignored |
| `'avg'` | Arithmetic mean | Non-numeric values excluded from count |
| `'count'` | Number of rows in the group | Counts all rows including blanks |
| `'min'` | Smallest numeric value | Non-numeric values ignored |
| `'max'` | Largest numeric value | Non-numeric values ignored |
| `'first'` | Value from the first row in the group | May be `undefined` if group is empty |
| `'last'` | Value from the last row in the group | May be `undefined` if group is empty |

You can also provide a custom function:
```typescript
const valueFields: PivotValueField[] = [
  { field: 'revenue', aggFunc: 'sum', header: 'Total Revenue' },
  { field: 'margin', aggFunc: (values) => values.reduce((a, b) => a + b, 0) / values.length },
];
```

```ts
type AggFunc = "sum" | "avg" | "count" | "min" | "max" | "first" | "last" | CustomAggFunc
```
