# AggregatedExpressionFunction

Canonical page: https://www.adaptabletools.com/docs/reference/aggregatedexpressionfunction

Defines an AdapTableQL function that aggregates data

```ts title="TypeScript"
export interface AggregatedExpressionFunction 
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [category](https://www.adaptabletools.com/docs/reference/aggregatedexpressionfunction.md#category) | `string` | Freeform Functions-menu section for Alert Aggregated / Calculated Column<br/>Aggregated editors. Omit (or use `'Aggregation'`) to list under Aggregation;<br/>any other string becomes its own section label. |
| [cumulative](https://www.adaptabletools.com/docs/reference/aggregatedexpressionfunction.md#cumulative) | `boolean \| \{ currentValue: (context: `[`AggregatedExpressionCumulativeValueContext`](https://www.adaptabletools.com/docs/reference/aggregatedexpressioncumulativevaluecontext.md)`) => any; \}` | Accept a `CUMULATIVE([orderColumn])` clause, e.g.<br/>`MY_AGG{[notional], CUMULATIVE([tradeDate])}`.<br/><br/>- `true` — generic running variant: rows are visited in `CUMULATIVE`<br/> order (per `GROUP_BY` partition when grouped), `reducer` accumulates,<br/> and the value recorded for each row is `processAggregatedValue` (or<br/> the accumulator when absent) evaluated on the prefix so far.<br/>- object — override the per-row read with `currentValue` when<br/> `processAggregatedValue` is too expensive to run per row or the<br/> running value is not a function of the accumulator alone.<br/><br/>Declaring the capability also makes the clause known to validation, the<br/>Expression Editor clause chips / Cumulative editor and the Query Builder. |
| [description](https://www.adaptabletools.com/docs/reference/aggregatedexpressionfunction.md#description) | `string` | What the aggregation evaluates to (outcome), shown in editor<br/>documentation. Often starts with &quot;Returns …&quot;. |
| [examples](https://www.adaptabletools.com/docs/reference/aggregatedexpressionfunction.md#examples) | `string[]` | Examples to use the Aggregated Expression Function |
| [filterRow](https://www.adaptabletools.com/docs/reference/aggregatedexpressionfunction.md#filterrow) | `(context: `[`AggregatedExpressionFilterRowContext`](https://www.adaptabletools.com/docs/reference/aggregatedexpressionfilterrowcontext.md)`) => boolean` | Optional filter which is applied to each row before the reducer is called. If the filter returns false, the row is NOT included in the aggregation. |
| [initialValue](https://www.adaptabletools.com/docs/reference/aggregatedexpressionfunction.md#initialvalue) | `any` | Mandatory Initial Value for the aggregation.<br/><br/>May be a plain value or a factory function returning a fresh value.<br/>Use a factory when the reducer mutates its accumulator (objects, arrays,<br/>Maps, Sets) — plain object values are deep-cloned per aggregation run<br/>(and per group) for backward compatibility, which is slower. |
| [inputTypes](https://www.adaptabletools.com/docs/reference/aggregatedexpressionfunction.md#inputtypes) | `ExpressionFunctionInputType[]` | Optional argument types. |
| [isAvailable](https://www.adaptabletools.com/docs/reference/aggregatedexpressionfunction.md#isavailable) | [`AdaptableAggregatedExpressionModule`](https://www.adaptabletools.com/docs/reference/adaptableaggregatedexpressionmodule.md)`[] \| ((context: `[`ExpressionFunctionAvailabilityContext`](https://www.adaptabletools.com/docs/reference/expressionfunctionavailabilitycontext.md)`) => boolean)` | Where the function is available — same semantics as standard<br/>`isAvailable`, but restricted to <br/>(Alert Aggregated and Calculated Column Aggregated).<br/>`undefined` means both aggregated expression modules. |
| [prepareRowValue](https://www.adaptabletools.com/docs/reference/aggregatedexpressionfunction.md#preparerowvalue) | `(context: `[`AggregatedExpressionPrepareRowValueContext`](https://www.adaptabletools.com/docs/reference/aggregatedexpressionpreparerowvaluecontext.md)`) => number \| string \| boolean \| Date \| undefined` | Called for each row AFTER the reducer() and processAggregatedValue() functions<br/>Can be used when each row has a different aggregated value (e.g. percentage = row value / aggregated value).<br/>Returns return value for each individual row (a boolean suits a boolean Calculated Column, e.g. &quot;is in the top K&quot;) |
| [processAggregatedValue](https://www.adaptabletools.com/docs/reference/aggregatedexpressionfunction.md#processaggregatedvalue) | `(context: `[`AggregatedExpressionProcessAggValueContext`](https://www.adaptabletools.com/docs/reference/aggregatedexpressionprocessaggvaluecontext.md)`) => any` | Called AFTER the reducer() has processed all values / rows<br/>Can be used to change result of reducer based on the values array (e.g. average = aggregated value / count) |
| [reducer](https://www.adaptabletools.com/docs/reference/aggregatedexpressionfunction.md#reducer) | `(context: `[`AggregatedExpressionReducerContext`](https://www.adaptabletools.com/docs/reference/aggregatedexpressionreducercontext.md)`) => any` | Mandatory Reducer function which is called for each value(row) in the Column Data |
| [returnType](https://www.adaptabletools.com/docs/reference/aggregatedexpressionfunction.md#returntype) | [`AggregatedExpressionReturnType`](https://www.adaptabletools.com/docs/reference/aggregatedexpressionreturntype.md) | Static result type of the aggregation. Drives the Calculated Column data<br/>type, the outer expression type check and editor documentation.<br/>`'input'` = same type as the aggregated column (MIN / MAX style). When<br/>omitted the result type is unknown (Calculated Columns default to number). |
| [signatures](https://www.adaptabletools.com/docs/reference/aggregatedexpressionfunction.md#signatures) | `string[]` | Example Signatures for the Aggregated Expression Function |
| [weight](https://www.adaptabletools.com/docs/reference/aggregatedexpressionfunction.md#weight) | `boolean` | Accept a `WEIGHT([column])` clause, e.g.<br/>`MY_VWAP{[price], WEIGHT([quantity])}`. The resolved weight of the<br/>current row is delivered as `weightValue` on the `reducer`,<br/>`prepareRowValue` and `filterRow` contexts (and on the cumulative<br/>`currentValue` context). |

## Property Details

### category

Freeform Functions-menu section for Alert Aggregated / Calculated Column
Aggregated editors. Omit (or use `'Aggregation'`) to list under Aggregation;
any other string becomes its own section label.

```ts title="TypeScript"
category?: string;
```

###### Property Value

`string`

### cumulative

Accept a `CUMULATIVE([orderColumn])` clause, e.g.
`MY_AGG{[notional], CUMULATIVE([tradeDate])}`.

- `true` — generic running variant: rows are visited in `CUMULATIVE`
 order (per `GROUP_BY` partition when grouped), `reducer` accumulates,
 and the value recorded for each row is `processAggregatedValue` (or
 the accumulator when absent) evaluated on the prefix so far.
- object — override the per-row read with `currentValue` when
 `processAggregatedValue` is too expensive to run per row or the
 running value is not a function of the accumulator alone.

Declaring the capability also makes the clause known to validation, the
Expression Editor clause chips / Cumulative editor and the Query Builder.

```ts title="TypeScript"
cumulative?: boolean | {
        currentValue: (context: AggregatedExpressionCumulativeValueContext) => any;
    };
```

###### Property Value

`boolean | \{ currentValue: (context: `[`AggregatedExpressionCumulativeValueContext`](https://www.adaptabletools.com/docs/reference/aggregatedexpressioncumulativevaluecontext.md)`) => any; \}`

### description

What the aggregation evaluates to (outcome), shown in editor
documentation. Often starts with &quot;Returns …&quot;.

```ts title="TypeScript"
description?: string;
```

###### Property Value

`string`

### examples

Examples to use the Aggregated Expression Function

```ts title="TypeScript"
examples?: string[];
```

###### Property Value

`string[]`

### filterRow

Optional filter which is applied to each row before the reducer is called. If the filter returns false, the row is NOT included in the aggregation.

```ts title="TypeScript"
filterRow?: (context: AggregatedExpressionFilterRowContext) => boolean;
```

###### Property Value

`(context: `[`AggregatedExpressionFilterRowContext`](https://www.adaptabletools.com/docs/reference/aggregatedexpressionfilterrowcontext.md)`) => boolean`

### initialValue

Mandatory Initial Value for the aggregation.

May be a plain value or a factory function returning a fresh value.
Use a factory when the reducer mutates its accumulator (objects, arrays,
Maps, Sets) — plain object values are deep-cloned per aggregation run
(and per group) for backward compatibility, which is slower.

```ts title="TypeScript"
initialValue: any;
```

###### Property Value

`any`

### inputTypes

Optional argument types.

```ts title="TypeScript"
inputTypes?: ExpressionFunctionInputType[];
```

###### Property Value

`ExpressionFunctionInputType[]`

### isAvailable

Where the function is available — same semantics as standard
`isAvailable`, but restricted to 
(Alert Aggregated and Calculated Column Aggregated).
`undefined` means both aggregated expression modules.

```ts title="TypeScript"
isAvailable?: AdaptableAggregatedExpressionModule[] | ((context: ExpressionFunctionAvailabilityContext) => boolean);
```

###### Property Value

[`AdaptableAggregatedExpressionModule`](https://www.adaptabletools.com/docs/reference/adaptableaggregatedexpressionmodule.md)`[] | ((context: `[`ExpressionFunctionAvailabilityContext`](https://www.adaptabletools.com/docs/reference/expressionfunctionavailabilitycontext.md)`) => boolean)`

### prepareRowValue

Called for each row AFTER the reducer() and processAggregatedValue() functions
Can be used when each row has a different aggregated value (e.g. percentage = row value / aggregated value).
Returns return value for each individual row (a boolean suits a boolean Calculated Column, e.g. &quot;is in the top K&quot;)

```ts title="TypeScript"
prepareRowValue?: (context: AggregatedExpressionPrepareRowValueContext) => number | string | boolean | Date | undefined;
```

###### Property Value

`(context: `[`AggregatedExpressionPrepareRowValueContext`](https://www.adaptabletools.com/docs/reference/aggregatedexpressionpreparerowvaluecontext.md)`) => number | string | boolean | Date | undefined`

### processAggregatedValue

Called AFTER the reducer() has processed all values / rows
Can be used to change result of reducer based on the values array (e.g. average = aggregated value / count)

```ts title="TypeScript"
processAggregatedValue?: (context: AggregatedExpressionProcessAggValueContext) => any;
```

###### Property Value

`(context: `[`AggregatedExpressionProcessAggValueContext`](https://www.adaptabletools.com/docs/reference/aggregatedexpressionprocessaggvaluecontext.md)`) => any`

### reducer

Mandatory Reducer function which is called for each value(row) in the Column Data

```ts title="TypeScript"
reducer: (context: AggregatedExpressionReducerContext) => any;
```

###### Property Value

`(context: `[`AggregatedExpressionReducerContext`](https://www.adaptabletools.com/docs/reference/aggregatedexpressionreducercontext.md)`) => any`

### returnType

Static result type of the aggregation. Drives the Calculated Column data
type, the outer expression type check and editor documentation.
`'input'` = same type as the aggregated column (MIN / MAX style). When
omitted the result type is unknown (Calculated Columns default to number).

```ts title="TypeScript"
returnType?: AggregatedExpressionReturnType;
```

###### Property Value

[`AggregatedExpressionReturnType`](https://www.adaptabletools.com/docs/reference/aggregatedexpressionreturntype.md)

### signatures

Example Signatures for the Aggregated Expression Function

```ts title="TypeScript"
signatures?: string[];
```

###### Property Value

`string[]`

### weight

Accept a `WEIGHT([column])` clause, e.g.
`MY_VWAP{[price], WEIGHT([quantity])}`. The resolved weight of the
current row is delivered as `weightValue` on the `reducer`,
`prepareRowValue` and `filterRow` contexts (and on the cumulative
`currentValue` context).

```ts title="TypeScript"
weight?: boolean;
```

###### Property Value

`boolean`
