# Standard Expressions

Canonical page: https://www.adaptabletools.com/docs/adaptable-ql-expression-standard

- A Standard Expression is evaluated against each row in isolation and returns a single value
- The return value is either:
  - **any** (scalar) — used in [Calculated Columns](https://www.adaptabletools.com/docs/handbook-calculated-column/index.md)
  - **boolean** — the most common form, used in Alerts, Grid Filter, Format Columns and many other Modules

A Standard Expression is evaluated against **each row in isolation** and returns **a single value**.

The return value is one of:

- **scalar** (any data type) — the value for that row
- **boolean** — `true` when the row passes every condition in the Expression

Standard Expressions are used in these Modules:

| Module                                                                      | Usage                                                       | Type    |
| --------------------------------------------------------------------------- | ----------------------------------------------------------- | ------- |
| [Alerts](https://www.adaptabletools.com/docs/handbook-alerting/index.md)                      | Triggers an Alert when data change matches a Rule           | Boolean |
| [Calculated Column](https://www.adaptabletools.com/docs/handbook-calculated-column/index.md)  | Evaluates the value displayed in the column                 | Scalar  |
| [Column Filter](https://www.adaptabletools.com/docs/handbook-column-filter/index.md)          | Boolean operators (AdapTableQL Functions) or a full Expression | Boolean |
| [Export](https://www.adaptabletools.com/docs/handbook-exporting/index.md)                     | Custom Reports export only those rows returned by the Expression | Boolean |
| [Flashing Cell](https://www.adaptabletools.com/docs/handbook-flashing-cell/index.md)          | [Relative Change](https://www.adaptabletools.com/docs/adaptable-ql-expression-relative-change/index.md) rule on a cell update | Relative Change |
| [Format Column](https://www.adaptabletools.com/docs/handbook-column-formatting/index.md)      | Sets whether or not to show the Format Column               | Boolean |
| [Grid Filter](https://www.adaptabletools.com/docs/handbook-grid-filter/index.md)              | Returns rows which match the true / false condition         | Boolean |
| [Named Query](https://www.adaptabletools.com/docs/handbook-named-queries/index.md)            | A saved Standard Expression reused via `QUERY`              | Any return type |
| [Plus Minus](https://www.adaptabletools.com/docs/handbook-editing-plus-minus/index.md)        | Manages evaluation of Custom Nudge Values                   | Boolean |
| [Styled Column](https://www.adaptabletools.com/docs/handbook-styled-column-overview/index.md) | Whether a Badge (or other style rule) renders               | Boolean |

[Relative Change Expressions](https://www.adaptabletools.com/docs/adaptable-ql-expression-relative-change/index.md) are a specialist Standard form used in Alerts and Flashing Cell

## Boolean Standard Expressions

Many Modules in AdapTable need `true` or `false` evaluation per row: 

e.g. A Grid Filter that shows rows where the smaller of two bids is over 50, or the currency is Dollar:

```ts [[2, 1, "MIN"], [1, 1, "BloombergBid"], [1, 1, "MarkitBid"],[2, 1, ">"],[4, 1, "50"],[3, 1, "OR"], [1, 1, "Currency"],  [4, 1, "USD"]]
 MIN([BloombergBid], [MarkitBid]) > 50 OR [Currency] = 'USD'
```

Or a Format Column condition for all positive columns in Scope:

```ts [[2, 1, "IS_POSITIVE"],[1, 1, "$SCOPE"]]
 IS_POSITIVE($SCOPE)
```

Or an Alert Rule if you have 50 Open Issues in JavaScript rows:

```ts [[1, 1, "open_issues_count"], [2, 1, ">"], [4, 1, "50"], [3, 1, "AND"], [1, 1, "language"], [4, 1, "JavaScript"]]
 [open_issues_count] > 50 AND [language] = "JavaScript"
```

**Example: AdapTableQL: Standard Expressions**

Using Standard Expressions in AdapTable

- This demo shows a number of different Standard Expressions:
- We have 4 Boolean Expressions applied to different AdapTable Modules:
  - A [Grid Filter](https://www.adaptabletools.com/docs/handbook-grid-filter/index.md) is filtering the grid for rows where `Language` is _JavaScript_
  - The [Export](https://www.adaptabletools.com/docs/handbook-exporting/index.md) module contains an `MIT Report` that exports rows where `License` is _MIT License_
  - A [Format Column Condition](https://www.adaptabletools.com/docs/handbook-column-formatting-conditions/index.md) is applied to rows where `Github Stars` > 50,000
  - An [Alert](https://www.adaptabletools.com/docs/handbook-alerting/index.md) fires when the Rule is triggered that `Open Issues` > 50
- Additionally it contains a Scalar Expression applied to a [Calculated Column](https://www.adaptabletools.com/docs/handbook-calculated-column/index.md) - `Full Github` - which adds `Github Stars` and `Github Watchers`

Demo project (Vanilla); the files without a marker are shown below:

```text
src/
  adaptableOptions.ts
  agGridModules.ts     [template]
  columnDefs.ts        [template]
  gridOptions.ts       [template]
  index.ts             [template]
  onAdaptableReady.ts  [template]
  rowData.ts           [template]
  styles.css           [template]
index.html             [template]
package.json           [template]
tsconfig.json          [template]
```

Files marked `[template]` are the same in every demo; see the [demo template](https://www.adaptabletools.com/llms/demo-template.md#vanilla).

**`src/adaptableOptions.ts`**

```ts
import {AdaptableOptions} from '@adaptabletools/adaptable';
import {WebFramework} from './rowData';

export const adaptableOptions: AdaptableOptions<WebFramework> = {
  primaryKey: 'id',
  adaptableId: 'Standard Expressions',
  initialState: {
    Dashboard: {
      Tabs: [
        {
          Name: 'Demo',
          Toolbars: ['GridFilter', 'Export', 'Alert'],
        },
      ],
    },
    StatusBar: {
      StatusBars: [
        {
          Key: 'Center Panel',
          StatusBarPanels: ['Export', 'Alert', 'GridFilter'],
        },
      ],
    },
    Theme: {CurrentTheme: 'dark'},
    CalculatedColumn: {
      CalculatedColumns: [
        {
          ColumnId: 'full_Github',
          FriendlyName: 'Full Github',
          Expression: '[github_stars] + [github_watchers]',
          CalculatedColumnSettings: {
            DataType: 'number',
          },
        },
      ],
    },
    Export: {
      CurrentReport: 'MIT Report',
      CurrentFormat: 'JSON',
      Reports: [
        {
          Name: 'MIT Report',
          ReportColumnScope: 'ScopeColumns',
          ReportRowScope: 'ExpressionRows',
          Scope: {
            ColumnIds: ['name', 'language', 'topics', 'license', 'updated_at'],
          },
          Expression: " [license] = 'MIT License'",
        },
      ],
    },
    FormatColumn: {
      FormatColumns: [
        {
          Name: 'style-all',
          Style: {
            BackColor: 'var(--ab-color-palette-26)',
            ForeColor: 'var(--ab-color-palette-13)',
          },
          Scope: {
            All: true,
          },
          Rule: '[github_stars] > 50000 ',
        },
      ],
    },
    Alert: {
      AlertDefinitions: [
        {
          Name: 'alert-Warning-42',
          MessageType: 'Warning',
          Scope: {
            All: true,
          },
          Rule: '[open_issues_count] > 50 ',
          AlertProperties: {
            DisplayNotification: true,
          },
        },
      ],
    },
    Layout: {
      CurrentLayout: 'Standard Layout',
      Layouts: [
        {
          TableColumns: [
            'name',
            'language',
            'open_issues_count',
            'license',
            'github_watchers',
            'github_stars',
            'full_Github',
            'created_at',
            'has_wiki',
            'updated_at',
            'pushed_at',
            'closed_issues_count',
            'open_pr_count',
            'closed_pr_count',
            'has_projects',
            'has_pages',
            'week_issue_change',
          ],
          Name: 'Standard Layout',
          GridFilter: {
            Expression: '[language]="JavaScript" ',
          },
          AutoSizeColumns: true,
        },
      ],
    },
  },
};
```

## Scalar Standard Expressions

A Calculated Column evaluates a value for each row:

```ts [[1, 1, "github_stars"], [2, 1, "+"], [1, 1, "github_watchers"]]
[github_stars] + [github_watchers];
```

```ts [[2, 1, "CONCAT"], [1, 1, "currency"], [1, 1, "country"]]
 CONCAT([currency], '-', [country]);
```

```ts [[1, 1, "ShippedDate"], [2, 1, ">"], [2, 1, "ADD_DAYS"], [1, 1, "OrderDate"], [4, 1, "21"], [4, 1, "Delayed"], [4, 1, "On time"]]
[ShippedDate] > ADD_DAYS([OrderDate], 21) ? 'Delayed' : 'On time';
```

A scalar [Named Query](https://www.adaptabletools.com/docs/handbook-named-queries/index.md) can hold the same kind of Expression and be reused with `QUERY`.

See the [Guide to Writing Expressions](https://www.adaptabletools.com/docs/adaptable-ql-expression-writing/index.md) for columns, operators, shortcuts, `AND` / `OR` and `WHERE`
