# ExpressionApi

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

Functions related to Expressions in AdapTableQL (the Adaptable Query Language)

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

## Methods

| Method | Returns | Description |
| --- | --- | --- |
| [evaluateAggregatedExpression(request)](https://www.adaptabletools.com/docs/reference/expressionapi.md#evaluateaggregatedexpression) | [`ExpressionEvaluationResult`](https://www.adaptabletools.com/docs/reference/expressionevaluationresult.md)`<`[`AggregatedExpressionEvaluationValue`](https://www.adaptabletools.com/docs/reference/aggregatedexpressionevaluationvalue.md)`>` | Evaluates an Aggregation Expression (e.g. `SUM{[price]}`,<br/>`MAX{[price], GROUP_BY([make])}`, `RANK{OVER([price])}`, `SUM{[price]} > 1000`)<br/>and returns a materialized snapshot: the global value, per-group values<br/>(for `GROUP_BY`) and a per-row projection (`getValueForRow`).<br/><br/>When the Expression is a condition, `matches` is whether at least one<br/>aggregation group satisfies it.<br/><br/>Default target is all loaded grid rows. Pass `dataSet` to aggregate a<br/>caller-supplied array, or `rowScope` / `rowFilter` to narrow the grid<br/>set. The snapshot does not update on data changes — re-evaluate when needed.<br/><br/>Under the server-side row model only currently loaded rows are aggregated;<br/>inspect `rowCount` to detect partial data. |
| [evaluateStandardExpression(request)](https://www.adaptabletools.com/docs/reference/expressionapi.md#evaluatestandardexpression) | [`ExpressionEvaluationResult`](https://www.adaptabletools.com/docs/reference/expressionevaluationresult.md)`<unknown>` | Evaluates a Standard Expression against a row.<br/>Requires a row target (`rowNode`, `primaryKeyValue`, or `data`) on the request.<br/>Never throws — returns a result envelope with `success` / `errorMessage`.<br/><br/>The Expression decides the return value: a condition such as `[price] > 100`<br/>yields `true` / `false`; `[price] * 1.19` yields a number.<br/><br/>Direct API evaluation ignores `expressionOptions.evaluateAdaptableQLExternally`<br/>(that option only skips evaluation inside AdapTable features). |
| [filterDataSet(request)](https://www.adaptabletools.com/docs/reference/expressionapi.md#filterdataset) | [`ExpressionEvaluationResult`](https://www.adaptabletools.com/docs/reference/expressionevaluationresult.md)`<Record<string, unknown>[]>` | Returns the subset of `dataSet` matching a boolean Expression, in original<br/>order and with the same object references. Validation runs once; a<br/>per-row evaluation error fails the whole call. |
| [filterRowNodes(request)](https://www.adaptabletools.com/docs/reference/expressionapi.md#filterrownodes) | [`ExpressionEvaluationResult`](https://www.adaptabletools.com/docs/reference/expressionevaluationresult.md)`<IRowNode[]>` | Returns the grid rows matching a boolean Expression, scoped by `rowScope`<br/>and optionally pre-narrowed by `rowFilter`. Validation runs once; a<br/>per-row evaluation error fails the whole call. Matching `IRowNode`s are<br/>returned in source order. |
| [getASTForExpression(expression)](https://www.adaptabletools.com/docs/reference/expressionapi.md#getastforexpression) | `any` | AST for remote / SSRM evaluation. Emits a normalized contract-v2 tree<br/>when `expressionOptions.supportedAstContractVersions` includes `2`;<br/>otherwise the raw parse tree (v1). |
| [getColumnsFromExpression(expression)](https://www.adaptabletools.com/docs/reference/expressionapi.md#getcolumnsfromexpression) | `string[]` | Returns all Columns referenced in an Expression |
| [getExpressionKind(expression, module)](https://www.adaptabletools.com/docs/reference/expressionapi.md#getexpressionkind) | [`ExpressionKind`](https://www.adaptabletools.com/docs/reference/expressionkind.md) | Infers the kind of an Expression from its text: `aggregated` when it contains an<br/>aggregation (e.g. `SUM{[col]}`), `scalar` otherwise — observable reads such as<br/>`CHANGE_COUNT{[col], WITHIN(5m)}` are scalar. Empty or unparseable text yields `scalar`. |
| [getExpressionWithColumnFriendlyNames(expression)](https://www.adaptabletools.com/docs/reference/expressionapi.md#getexpressionwithcolumnfriendlynames) | `string \| undefined` | Returns the Expression with Column Headers in place of Column IDs |
| [isColumnQueryable(abColumn)](https://www.adaptabletools.com/docs/reference/expressionapi.md#iscolumnqueryable) | `boolean` | Whether a column can be used in an AdapTableQL expression. |
| [isValidAggregatedExpression(expression, module, validationErrorMessage)](https://www.adaptabletools.com/docs/reference/expressionapi.md#isvalidaggregatedexpression) | `boolean` | Whether the given AggregatedExpression is valid |
| [isValidScalarExpression(expression, module, validationErrorMessage)](https://www.adaptabletools.com/docs/reference/expressionapi.md#isvalidscalarexpression) | `boolean` | Whether the given Expression is valid as a boolean predicate (Alert / Format Column /<br/>Grid Filter / etc.). Root `QUERY("x")` is accepted only when the named query&#39;s<br/>declared ReturnType is boolean (or absent). |
| [isValidValueExpression(expression, module, validationErrorMessage)](https://www.adaptabletools.com/docs/reference/expressionapi.md#isvalidvalueexpression) | `boolean` | Whether the given Expression is a valid value-producing scalar expression<br/>(any return type — used by Calculated Column and non-boolean Named Queries). |
| [migratePreV24Expression(expression, options)](https://www.adaptabletools.com/docs/reference/expressionapi.md#migrateprev24expression) | `\{ expression: string; changed: boolean; error?: string; \}` | Convert a leftover (pre-v24) AdaptableQL string to the v24 greenfield<br/>syntax. Unparseable input is returned unchanged with `error` set.<br/><br/>v24 introduced brace aggregations (`SUM{[price]}`), named operands<br/>(`CUMULATIVE([d])`, `WITHIN(5m)`), and dropped wrappers such as<br/>`CUMUL(...)` and `TIMEFRAME(...)`. Persisted state is rewritten on<br/>load by VersionUpgrade24 when `autoMigrateState` is on. Use this for<br/>a single programmatic / external-config string that has not gone<br/>through that upgrade. The runtime does not accept leftover spellings.<br/><br/>`expressionKind` is the stored module kind. Required for dual-name<br/>paren calls (`SUM([x])` scalar vs aggregation). Omit only when the<br/>leftover is shape-proven (`GROUP_BY` / `CUMUL` / `TIMEFRAME` / …). |
| [shouldEvaluateDatesUsingTime(column)](https://www.adaptabletools.com/docs/reference/expressionapi.md#shouldevaluatedatesusingtime) | `boolean` | Whether date comparisons use the full timestamp (exact instant) rather than<br/>the calendar day for the given column — governs the `IN` operator on date<br/>columns and the date Column Filter&#39;s distinct-value tree granularity. |
| [useCaseSensitivity()](https://www.adaptabletools.com/docs/reference/expressionapi.md#usecasesensitivity) | `boolean` | Whether Expressions are evaluated using Case Sensitivity |

## Method Details

### evaluateAggregatedExpression

Evaluates an Aggregation Expression (e.g. `SUM{[price]}`,
`MAX{[price], GROUP_BY([make])}`, `RANK{OVER([price])}`, `SUM{[price]} > 1000`)
and returns a materialized snapshot: the global value, per-group values
(for `GROUP_BY`) and a per-row projection (`getValueForRow`).

When the Expression is a condition, `matches` is whether at least one
aggregation group satisfies it.

Default target is all loaded grid rows. Pass `dataSet` to aggregate a
caller-supplied array, or `rowScope` / `rowFilter` to narrow the grid
set. The snapshot does not update on data changes — re-evaluate when needed.

Under the server-side row model only currently loaded rows are aggregated;
inspect `rowCount` to detect partial data.

```ts title="TypeScript"
evaluateAggregatedExpression(request: EvaluateAggregatedExpressionRequest): ExpressionEvaluationResult<AggregatedExpressionEvaluationValue>;
```

###### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| request | [`EvaluateAggregatedExpressionRequest`](https://www.adaptabletools.com/docs/reference/evaluateaggregatedexpressionrequest.md) | Expression + optional module / dataSet / rowScope / rowFilter |

###### Returns

 Evaluates an Aggregation Expression (e.g. `SUM{[price]}`, `MAX{[price], GROUP_BY([make])}`, `RANK{OVER([price])}`, `SUM{[price]} > 1000`) and returns a materialized snapshot: the global value, per-group values (for `GROUP_BY`) and a per-row projection (`getValueForRow`). When the Expression is a condition, `matches` is whether at least one aggregation group satisfies it. Default target is all loaded grid rows. Pass `dataSet` to aggregate a caller-supplied array, or `rowScope` / `rowFilter` to narrow the grid set. The snapshot does not update on data changes — re-evaluate when needed. Under the server-side row model only currently loaded rows are aggregated; inspect `rowCount` to detect partial data

[`ExpressionEvaluationResult`](https://www.adaptabletools.com/docs/reference/expressionevaluationresult.md)`<`[`AggregatedExpressionEvaluationValue`](https://www.adaptabletools.com/docs/reference/aggregatedexpressionevaluationvalue.md)`>`

### evaluateStandardExpression

Evaluates a Standard Expression against a row.
Requires a row target (`rowNode`, `primaryKeyValue`, or `data`) on the request.
Never throws — returns a result envelope with `success` / `errorMessage`.

The Expression decides the return value: a condition such as `[price] > 100`
yields `true` / `false`; `[price] * 1.19` yields a number.

Direct API evaluation ignores `expressionOptions.evaluateAdaptableQLExternally`
(that option only skips evaluation inside AdapTable features).

```ts title="TypeScript"
evaluateStandardExpression(request: EvaluateStandardExpressionRequest): ExpressionEvaluationResult<unknown>;
```

###### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| request | [`EvaluateStandardExpressionRequest`](https://www.adaptabletools.com/docs/reference/evaluatestandardexpressionrequest.md) | Expression + exactly one row target (`rowNode` / `primaryKeyValue` / `data`) |

###### Returns

 Evaluates a Standard Expression against a row. Requires a row target (`rowNode`, `primaryKeyValue`, or `data`) on the request. Never throws — returns a result envelope with `success` / `errorMessage`. The Expression decides the return value: a condition such as `[price] > 100` yields `true` / `false`; `[price] * 1.19` yields a number. Direct API evaluation ignores `expressionOptions.evaluateAdaptableQLExternally` (that option only skips evaluation inside AdapTable features)

[`ExpressionEvaluationResult`](https://www.adaptabletools.com/docs/reference/expressionevaluationresult.md)`<unknown>`

### filterDataSet

Returns the subset of `dataSet` matching a boolean Expression, in original
order and with the same object references. Validation runs once; a
per-row evaluation error fails the whole call.

```ts title="TypeScript"
filterDataSet(request: FilterDataSetRequest): ExpressionEvaluationResult<Record<string, unknown>[]>;
```

###### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| request | [`FilterDataSetRequest`](https://www.adaptabletools.com/docs/reference/filterdatasetrequest.md) | Expression + the array to filter |

###### Returns

 The subset of `dataSet` matching a boolean Expression, in original order and with the same object references. Validation runs once; a per-row evaluation error fails the whole call

[`ExpressionEvaluationResult`](https://www.adaptabletools.com/docs/reference/expressionevaluationresult.md)`<Record<string, unknown>[]>`

### filterRowNodes

Returns the grid rows matching a boolean Expression, scoped by `rowScope`
and optionally pre-narrowed by `rowFilter`. Validation runs once; a
per-row evaluation error fails the whole call. Matching `IRowNode`s are
returned in source order.

```ts title="TypeScript"
filterRowNodes(request: FilterRowNodesRequest): ExpressionEvaluationResult<IRowNode[]>;
```

###### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| request | [`FilterRowNodesRequest`](https://www.adaptabletools.com/docs/reference/filterrownodesrequest.md) | Expression + optional rowScope / rowFilter / cellValueOverride / module |

###### Returns

 The grid rows matching a boolean Expression, scoped by `rowScope` and optionally pre-narrowed by `rowFilter`. Validation runs once; a per-row evaluation error fails the whole call. Matching `IRowNode`s are returned in source order

[`ExpressionEvaluationResult`](https://www.adaptabletools.com/docs/reference/expressionevaluationresult.md)`<IRowNode[]>`

### getASTForExpression

AST for remote / SSRM evaluation. Emits a normalized contract-v2 tree
when `expressionOptions.supportedAstContractVersions` includes `2`;
otherwise the raw parse tree (v1).

```ts title="TypeScript"
getASTForExpression(expression: string): any;
```

###### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| expression | `string` | Expression to parse |

###### Returns

 AST for remote / SSRM evaluation. Emits a normalized contract-v2 tree when `expressionOptions.supportedAstContractVersions` includes `2`; otherwise the raw parse tree (v1)

`any`

### getColumnsFromExpression

Returns all Columns referenced in an Expression

```ts title="TypeScript"
getColumnsFromExpression(expression: string): string[];
```

###### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| expression | `string` | expression to check |

###### Returns

 All Columns referenced in an Expression

`string[]`

### getExpressionKind

Infers the kind of an Expression from its text: `aggregated` when it contains an
aggregation (e.g. `SUM{[col]}`), `scalar` otherwise — observable reads such as
`CHANGE_COUNT{[col], WITHIN(5m)}` are scalar. Empty or unparseable text yields `scalar`.

```ts title="TypeScript"
getExpressionKind(expression: string, module?: AdaptableModule): ExpressionKind;
```

###### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| expression | `string` | the AdaptableQL Expression |
| module | [`AdaptableModule`](https://www.adaptabletools.com/docs/reference/adaptablemodule.md) | module whose custom functions are taken into account (default `'Expression'`) |

###### Returns

 Infers the kind of an Expression from its text: `aggregated` when it contains an aggregation (e.g. `SUM{[col]}`), `scalar` otherwise — observable reads such as `CHANGE_COUNT{[col], WITHIN(5m)}` are scalar. Empty or unparseable text yields `scalar`

[`ExpressionKind`](https://www.adaptabletools.com/docs/reference/expressionkind.md)

### getExpressionWithColumnFriendlyNames

Returns the Expression with Column Headers in place of Column IDs

```ts title="TypeScript"
getExpressionWithColumnFriendlyNames(expression: string | undefined | null): string | undefined;
```

###### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| expression | `string \| undefined \| null` | the Expression string |

###### Returns

 The Expression with Column Headers in place of Column IDs

`string | undefined`

### isColumnQueryable

Whether a column can be used in an AdapTableQL expression.

```ts title="TypeScript"
isColumnQueryable(abColumn: AdaptableColumn): boolean;
```

###### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| abColumn | [`AdaptableColumn`](https://www.adaptabletools.com/docs/reference/adaptablecolumn.md) | Column to check |

###### Returns

 `true` when a column can be used in an AdapTableQL expression

`boolean`

### isValidAggregatedExpression

Whether the given AggregatedExpression is valid

```ts title="TypeScript"
isValidAggregatedExpression(expression: string, module: AdaptableModule, validationErrorMessage?: string): boolean;
```

###### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| expression | `string` | AggregatedExpression to check |
| module | [`AdaptableModule`](https://www.adaptabletools.com/docs/reference/adaptablemodule.md) | module specific query |
| validationErrorMessage | `string` | optional validation error message; if provided, the error will be logged |

###### Returns

 `true` when the given AggregatedExpression is valid

`boolean`

### isValidScalarExpression

Whether the given Expression is valid as a boolean predicate (Alert / Format Column /
Grid Filter / etc.). Root `QUERY("x")` is accepted only when the named query&#39;s
declared ReturnType is boolean (or absent).

```ts title="TypeScript"
isValidScalarExpression(expression: string, module: AdaptableModule, validationErrorMessage?: string): boolean;
```

###### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| expression | `string` | query to Check |
| module | [`AdaptableModule`](https://www.adaptabletools.com/docs/reference/adaptablemodule.md) | module specific query |
| validationErrorMessage | `string` | optional validation error message; if provided, the error will be logged |

###### Returns

 `true` when the given Expression is valid as a boolean predicate (Alert / Format Column / Grid Filter / etc.). Root `QUERY("x")` is accepted only when the named query&#39;s declared ReturnType is boolean (or absent)

`boolean`

### isValidValueExpression

Whether the given Expression is a valid value-producing scalar expression
(any return type — used by Calculated Column and non-boolean Named Queries).

```ts title="TypeScript"
isValidValueExpression(expression: string, module: AdaptableModule, validationErrorMessage?: string): boolean;
```

###### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| expression | `string` | Expression to check |
| module | [`AdaptableModule`](https://www.adaptabletools.com/docs/reference/adaptablemodule.md) | Module the expression belongs to |
| validationErrorMessage | `string` | When set, the validation error is logged with this message |

###### Returns

 `true` when the given Expression is a valid value-producing scalar expression (any return type — used by Calculated Column and non-boolean Named Queries)

`boolean`

### migratePreV24Expression

Convert a leftover (pre-v24) AdaptableQL string to the v24 greenfield
syntax. Unparseable input is returned unchanged with `error` set.

v24 introduced brace aggregations (`SUM{[price]}`), named operands
(`CUMULATIVE([d])`, `WITHIN(5m)`), and dropped wrappers such as
`CUMUL(...)` and `TIMEFRAME(...)`. Persisted state is rewritten on
load by VersionUpgrade24 when `autoMigrateState` is on. Use this for
a single programmatic / external-config string that has not gone
through that upgrade. The runtime does not accept leftover spellings.

`expressionKind` is the stored module kind. Required for dual-name
paren calls (`SUM([x])` scalar vs aggregation). Omit only when the
leftover is shape-proven (`GROUP_BY` / `CUMUL` / `TIMEFRAME` / …).

```ts title="TypeScript"
migratePreV24Expression(expression: string, options?: {
        expressionKind?: 'boolean' | 'scalar' | 'aggregatedScalar' | 'aggregatedBoolean';
    }): {
        expression: string;
        changed: boolean;
        error?: string;
    };
```

###### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| expression | `string` | Expression written in the older syntax |
| options | `\{ expressionKind?: 'boolean' \| 'scalar' \| 'aggregatedScalar' \| 'aggregatedBoolean'; \}` | `expressionKind` is the stored module kind. Required for calls such as `SUM([x])` that can be either a scalar or an aggregation |

###### Returns

 Convert a leftover (pre-v24) AdaptableQL string to the v24 greenfield syntax. Unparseable input is returned unchanged with `error` set. v24 introduced brace aggregations (`SUM{[price]}`), named operands (`CUMULATIVE([d])`, `WITHIN(5m)`), and dropped wrappers such as `CUMUL(...)` and `TIMEFRAME(...)`. Persisted state is rewritten on load by VersionUpgrade24 when `autoMigrateState` is on. Use this for a single programmatic / external-config string that has not gone through that upgrade. The runtime does not accept leftover spellings. `expressionKind` is the stored module kind. Required for dual-name paren calls (`SUM([x])` scalar vs aggregation). Omit only when the leftover is shape-proven (`GROUP_BY` / `CUMUL` / `TIMEFRAME` / …)

`\{ expression: string; changed: boolean; error?: string; \}`

### shouldEvaluateDatesUsingTime

Whether date comparisons use the full timestamp (exact instant) rather than
the calendar day for the given column — governs the `IN` operator on date
columns and the date Column Filter&#39;s distinct-value tree granularity.

```ts title="TypeScript"
shouldEvaluateDatesUsingTime(column: string | AdaptableColumn): boolean;
```

###### Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| column | `string \| `[`AdaptableColumn`](https://www.adaptabletools.com/docs/reference/adaptablecolumn.md) | Column id or column to check |

###### Returns

 `true` when date comparisons use the full timestamp (exact instant) rather than the calendar day for the given column — governs the `IN` operator on date columns and the date Column Filter&#39;s distinct-value tree granularity

`boolean`

### useCaseSensitivity

Whether Expressions are evaluated using Case Sensitivity

```ts title="TypeScript"
useCaseSensitivity(): boolean;
```

###### Returns

 `true` when Expressions are evaluated using Case Sensitivity

`boolean`
