Adaptable

#Expressions

This page describes the syntax of AdaptableQL expressions and the functions you can use in them. For where expressions are used, see the AdaptableQL overview.

#Syntax

#Values

  • Numbers: 42, 0.5, -1.
  • Text, in double or single quotes: "TypeScript", 'Emma'. To include the quote character, double it: 'O''Brien'.
  • Booleans: TRUE, FALSE.
  • NULL for a missing value.
  • Dates have no literal form — build them with DATE: DATE(2026, 1, 31) or DATE("2026-01-31").

#Columns and fields

  • [columnId] — the value of a column, by column id. COL("columnId") does the same with the id as text.
  • FIELD("path") — a property of the row data that is not necessarily a column; dot notation reads nested properties. See Fields.
  • $SCOPE — in styled cells, alerts, flashing cells and column filters: the value of the column the rule is being evaluated for.

#Operators

OperatorMeaningExample
+ - * / % ^Arithmetic (% remainder, ^ power)[salary] / 12
= != < <= > >=Comparison[salary] >= 100000
CONTAINS, NOT_CONTAINSText contains / does not contain[country] CONTAINS "an"
STARTS_WITH, ENDS_WITHText starts / ends with[lastName] STARTS_WITH "S"
IN, NOT_INValue is (not) in a list[country] IN ("France", "Japan")
AND, ORLogical and / or (also & and |)[salary] > 100000 AND [country] = "France"
NOT, !Negation!([salary] > 100000)
? :Conditional (if / then / else)[salary] > 150000 ? "High" : "Low"

A few rules to keep in mind:

  • AND binds tighter than OR: a AND b OR c means (a AND b) OR c. Use parentheses when in doubt.
  • Wrap the negated condition in parentheses: !([salary] > 100000) or NOT([salary] > 100000). Without them, the negation only applies to [salary].
  • Comparisons can't be chained — [a] = [b] = [c] is an error; write [a] = [b] AND [b] = [c].
  • Keywords and function names are case-insensitive.
  • In Adaptable, text comparisons are case-insensitive: [preferredLanguage] = "typescript" matches "TypeScript".
  • Line breaks are only allowed inside parentheses or brackets.
  • Every operator also has a function form (EQ, NEQ, GT, GTE, LT, LTE, CONTAINS(a, b), SUM, SUB, PRODUCT, DIV, MOD, POW, AND, OR, NOT, IF).

#CASE

For more than two branches, CASE reads better than nested ? :. It has two forms:

CASE [preferredLanguage] WHEN "TypeScript" THEN "TS" WHEN "JavaScript" THEN "JS" ELSE "Other" END

CASE WHEN [salary] < 80000 THEN "Low" WHEN [salary] < 150000 THEN "Medium" ELSE "High" END

The first matches a value against each WHEN; the second picks the first WHEN condition that is true. ELSE is optional.

#Functions

Functions are called with parentheses: ROUND([salary] / 12, 2). The expression editors in the UI list every function with its description and examples, and offer them as completions.

#Logical and null handling

FunctionReturns
IF(condition, then, else)then if the condition is true, otherwise else — same as ? :
COALESCE(a, b, …)The first argument that is not null
IS_BLANK(value)True for null, undefined, empty text or an empty array
IS_NOT_BLANK(value)The opposite of IS_BLANK
IFERROR(value, fallback)value, or fallback if evaluating it fails
IFNA(value, fallback)value, or fallback if it is NA()
NA()An N/A error, to be caught by IFNA or IFERROR
NULL()The null value

#Numbers

FunctionReturns
ROUND(n), ROUND(n, digits)n rounded to digits decimal places (default 0)
FLOOR(n), CEILING(n)The nearest integer below / above
ABS(n), SIGN(n), SQRT(n)Absolute value, sign (-1, 0 or 1), square root
MIN(a, b, …), MAX(a, b, …), AVG(a, b, …)The smallest, largest or average of the arguments
IS_POSITIVE(n), IS_NEGATIVE(n)True if n is above / below zero
IS_NUMERIC(value)True if the value can be read as a number

SUM, SUB, PRODUCT, DIV, MOD and POW are the function forms of + - * / % ^.

#Text

FunctionReturns
CONCAT(a, b, …)The values joined, with no separator
TEXTJOIN(separator, ignoreEmpty, a, b, …)The values joined with separator, optionally skipping empty ones
LEN(text)The number of characters
LEFT(text, n), RIGHT(text, n)The first / last n characters
MID(text, start, n)n characters from position start (1-based)
SUB_STRING(text, start, end)The characters between two 0-based positions
UPPER(text), LOWER(text), TRIM(text)Upper case, lower case, surrounding whitespace removed
REPLACE(text, search, replacement)text with every occurrence of search replaced
REGEX(text, pattern)True if text matches the regular expression

#Dates

FunctionReturns
DATE(year, month, day), DATE("YYYY-MM-DD")A date (months are 1-based)
NOW(), CURRENT_DAY()The current date and time / today at midnight
DAY(d), WEEKDAY(d), WEEK(d), MONTH(d), QUARTER(d), YEAR(d)Parts of the date as numbers (WEEKDAY: 1 = Sunday … 7 = Saturday)
ADD_DAYS(d, n), ADD_WEEKS(d, n), ADD_MONTHS(d, n), ADD_YEARS(d, n)The date moved by n units
DIFF_DAYS(a, b), DIFF_WEEKS(a, b), DIFF_MONTHS(a, b), DIFF_YEARS(a, b)The number of whole units from b to a
START_OF_DAY(d), START_OF_WEEK(d), START_OF_MONTH(d), START_OF_QUARTER(d), START_OF_YEAR(d)The start of the period containing d
END_OF_MONTH(d)The last day of the month containing d
EDATE(d, months), EOMONTH(d, months)Excel-style month shifts: same day / last day of the month, months away
IS_PAST(d), IS_FUTURE(d)True if d is before / after the current instant
IS_BEFORE_TODAY(d), IS_AFTER_TODAY(d)True if the calendar day is before / after today
IS_THIS_WEEK(d), IS_THIS_MONTH(d), IS_THIS_QUARTER(d), IS_THIS_YEAR(d)True if d falls in the current period

Weeks start on Sunday.

#Changes

These functions compare a cell's new value with its previous one, so they only work in alerts and flashing cells, which react to data changes:

FunctionReturns
ANY_CHANGE(), ANY_CHANGE([col])True if the changed cell (or the given column) has a different value
PERCENT_CHANGE([col])The change as a percentage of the previous value
ABSOLUTE_CHANGE([col])The absolute difference between the previous and new value

PERCENT_CHANGE and ABSOLUTE_CHANGE also accept $SCOPE, and an optional "INCREASE" or "DECREASE" argument to only count changes in one direction — for example PERCENT_CHANGE($SCOPE, "INCREASE") > 10.

#Aggregations

Aggregation functions look at many rows. They use curly braces, with the column first:

AVG{[salary]}
Note

Braces aggregate a column over the rows — SUM{[salary]} is the total salary. Parentheses call the per-row function — SUM([salary], 1000) adds 1000 to each salary.

An aggregation returns the same value for every row, so it's usually combined with row values: [salary] - AVG{[salary]}, or as a condition, [salary] > AVG{[salary]}. Aggregations scan the full data set, not only the rows that pass the current filters.

FunctionReturns
SUM{[col]}, AVG{[col]}, MIN{[col]}, MAX{[col]}, PRODUCT{[col]}Sum, average, minimum, maximum, product
COUNT{[col]}The number of non-empty values
DISTINCT{[col]}The number of distinct values
MEDIAN{[col]}, MODE{[col]}The median / most frequent value
STD_DEVIATION{[col]}The population standard deviation
ONLY{[col]}The value, if every row has the same one; otherwise null
SUMIF{[col], condition}, COUNTIF{[col], condition}, AVGIF{[col], condition}Sum, count, average over the rows matching condition

#Clauses

Clauses go inside the braces, after the column:

  • GROUP_BY([col], …) — computes the aggregation separately for each distinct value, and gives each row the value of its own group: AVG{[salary], GROUP_BY([country])}.
  • WHERE condition — only rows matching the condition contribute: AVG{[salary] WHERE [country] = "France"}. After a whole expression, WHERE applies to every aggregation in it: SUM{[salary]} > 200000 WHERE [country] = "France".
  • WEIGHT([col]) — a weighted average: AVG{[salary], WEIGHT([hours])}.
  • CUMULATIVE([col]) — a running value, with rows ordered by the column. Works with SUM, AVG, MIN, MAX and COUNT: SUM{[salary], CUMULATIVE([id])}. Combine with GROUP_BY to restart the running value for each group.

#Window and quantile functions

Window functions read rows in the order given by OVER:

FunctionReturns
RANK{OVER([col])}The 1-based rank of the row (ties share a rank)
FIRST{[col], OVER([order])}, LAST{[col], OVER([order])}The first / last value of [col] in that order
LAG{[col], n, OVER([order])}, LEAD{[col], n, OVER([order])}The value n rows before / after

Quantile functions tell which bucket each row falls into:

FunctionReturns
QUARTILE{[col]}1–4
PERCENTILE{[col]}1–100
QUANT{[col], q}1–q

Window and quantile functions accept GROUP_BY too, to rank or bucket within each group.

Note

Aggregated, cumulative, window and quantile expressions are accepted in calculated columns, the grid filter and alerts. Styled cells, flashing cells, column filters, named queries and reports accept per-row expressions only.

#Named queries

A named query is a reusable expression with a name. Other expressions reference it with QUERY("name") — names are case-insensitive.

Named queries live in the namedQuery slice of the Adaptable state, keyed by id:

Named queries in state
const defaultState: AdaptableUserState = {
  namedQuery: {
    'high-earners': {
      name: 'HighEarners',
      expression: '[salary] > 110000',
      description: 'Salary over 110,000',
    },
  },
  view: {
    currentViewId: 'default',
    views: [{ id: 'default', label: 'Developers', filters: { grid: 'QUERY("HighEarners")' } }],
  },
};

QUERY can be combined with anything else — QUERY("HighEarners") AND [country] = "Japan" — and a named query can reference other named queries. Circular references are rejected. Named query expressions are evaluated per row; they can't contain aggregations.

#
Named queries

The grid filter is QUERY("HighEarners"), and a styled cell highlights the names of TypeScript developers with the condition QUERY("TypeScriptDevs"). Open the settings panel from the dashboard and go to Named Queries to see and edit them.

open
loading demo…

The settings panel's Named Queries page creates, edits and deletes named queries; it's also available standalone as Adaptable.UI.NamedQueriesManager. For custom UIs, use the useNamedQueries composable. It returns one ComputedRef of an object:

import { useNamedQueries } from '@adaptabletools/datagrid-vue';

// in the setup of a component inside Adaptable.Provider
const namedQueriesModel = useNamedQueries();

// a ComputedRef: read its value where you use it, so it is always current
function onSomeEvent() {
  const {
    namedQueries, // all named queries, sorted by name
    getNamedQueryByName, // (name) => named query, case-insensitive
    getReference, // (name) => 'QUERY("name")'
    getNameError, // (name, { ignoreId? }) => error message, or undefined
    createNamedQuery, // ({ name, expression, description?, id? }) => id
    updateNamedQuery, // (id, config) => void
    deleteNamedQuery, // (id) => void
  } = namedQueriesModel.value;

  // ...
}