# Add a column by condition

Shape / columns

if, case or switch expression to a column

Page: <https://meridian.online/operations/add-a-column-by-condition>

## Status

Runs as a SQL step.

arcform carries it as a `sql:` step today.

## The DuckDB step

a banded column

It reads the `orders` table the proofs share. Create it first:

```sql
CREATE TABLE orders AS SELECT * FROM (VALUES
  (1,  'Alice Ng',      'north', DATE '2026-01-03', 120.00, 'widget', 'a|b',   '{"channel":"web","items":[1,2]}'),
  (2,  'alice ng',      'north', DATE '2026-01-05',  80.50, 'gadget', 'b',     '{"channel":"shop","items":[3]}'),
  (3,  'Bob  Okafor',   'south', DATE '2026-01-05', 300.00, 'widget', 'a|c',   '{"channel":"web","items":[4,5,6]}'),
  (4,  'Carla Díaz',    'east',  DATE '2026-01-09',  NULL,  'gizmo',  NULL,    '{"channel":"web","items":[]}'),
  (5,  'Bob Okafor',    'south', DATE '2026-01-12',  45.25, 'gadget', 'c',     '{"channel":"phone","items":[7]}'),
  (6,  'Dev Patel',     'west',  DATE '2026-01-12', 510.00, 'widget', 'a',     '{"channel":"web","items":[8,9]}'),
  (7,  'Carla Diaz',    'east',  DATE '2026-01-20',  99.99, 'gizmo',  'b|c',   '{"channel":"shop","items":[10]}'),
  (8,  'Dev Patel',     'west',  DATE '2026-02-02', 510.00, 'widget', 'a',     '{"channel":"web","items":[8,9]}'),
  (9,  'Eve Larsen',    NULL,    DATE '2026-02-03',  15.00, 'gadget', NULL,    '{"channel":"web","items":[11]}'),
  (10, 'Alice Ng',      'north', DATE '2026-02-10', 220.00, 'gizmo',  'a|b|c', '{"channel":"phone","items":[12,13]}')
) t(order_id, customer, region, order_date, amount, product, tags, meta);
```

Then run the statement:

```sql
CREATE TEMP TABLE result AS
SELECT order_id, CASE WHEN amount IS NULL THEN 'unknown' WHEN amount >= 300 THEN 'large' WHEN amount >= 100 THEN 'medium' ELSE 'small' END AS band FROM orders;
SELECT * FROM result;
SELECT CASE WHEN ((SELECT map_from_entries(list((band, n) ORDER BY band)) = MAP {'large': 3, 'medium': 2, 'small': 4, 'unknown': 1} FROM (SELECT band, count(*) AS n FROM result GROUP BY band))) THEN 'as expected' ELSE error('the bands do not count 3 large, 2 medium, 4 small and 1 unknown') END AS verdict;
```

It needs nothing installed beyond DuckDB itself.

## What other tools call it

Meridian's classification; an independent blind rating agreed on 86.2% of 312 rows (exact class, version 2).

- Azure Data Factory: [`Logical functions`](https://learn.microsoft.com/en-us/azure/data-factory/control-flow-expression-language-functions) (read 2026-09-27)
- EasyMorph: [`Rule`](https://help.easymorph.com/doku.php?id=transformations:rule) (read 2026-09-27)
- Ibis: [`IfElse`](https://github.com/ibis-project/ibis/blob/05d2b293344e86cb41c1a426071734f7e270335a/ibis/expr/operations/logical.py) (read 2026-09-27)
- Ibis: [`SearchedCase`](https://github.com/ibis-project/ibis/blob/05d2b293344e86cb41c1a426071734f7e270335a/ibis/expr/operations/generic.py) (read 2026-09-27)
- Ibis: [`SimpleCase`](https://github.com/ibis-project/ibis/blob/05d2b293344e86cb41c1a426071734f7e270335a/ibis/expr/operations/generic.py) (read 2026-09-27)
- KNIME Analytics Platform: [`Column Comparator`](https://api.hub.knime.com/nodes/*vy_dP5yr5m6ZVMPE?details=full) (read 2026-09-27)
- KNIME Analytics Platform: [`Rule Engine`](https://api.hub.knime.com/nodes/*zpGPAjDyExkFL2HB?details=full) (read 2026-09-27)
- KNIME Analytics Platform: [`Rule Engine (Dictionary)`](https://api.hub.knime.com/nodes/*GpUdH91fJl4_KfiB?details=full) (read 2026-09-27)
- KNIME Analytics Platform: [`Ruleset Editor`](https://api.hub.knime.com/nodes/*0Y5y2-u7yUx5ohSu?details=full) (read 2026-09-27)
- Apache NiFi: [`Boolean Logic`](https://nifi.apache.org/nifi-docs/expression-language-guide.html) (read 2026-09-27)
- OpenRefine: [`Controls`](https://openrefine.org/docs/manual/grel#controls) (read 2026-09-27)
- Polars: [`SQL functions: Conditional (group)`](https://docs.pola.rs/api/python/stable/reference/sql/functions/conditional.html) (read 2026-09-27)
- Polars: [`when`](https://docs.pola.rs/api/python/stable/reference/expressions/functions.html) (read 2026-09-27)
- Apache SeaTunnel: [`System Functions`](https://seatunnel.apache.org/docs/2.3.13/transforms/sql-functions) (read 2026-09-27)
- Tableau Prep: [`Keywords (group)`](https://help.tableau.com/current/prep/en-us/prep_function_reference.htm) (read 2026-09-27)
- Tableau Prep: [`Logical functions (group)`](https://help.tableau.com/current/prep/en-us/prep_function_reference.htm) (read 2026-09-27)
- Trifacta: [`Case Transform`](https://help.alteryx.com/aac/en/trifacta-classic/wrangle-language/language-appendices/transforms.html) (read 2026-09-27)
- Trifacta: [`Comparison Functions (group)`](https://help.alteryx.com/aac/en/trifacta-classic/wrangle-language/comparison-functions.html) (read 2026-09-27)
- Trifacta: [`Comparison Operators`](https://help.alteryx.com/aac/en/trifacta-classic/wrangle-language/comparison-functions/comparison-operators.html) (read 2026-09-27)
- Trifacta: [`Conditional column`](https://help.alteryx.com/aac/en/trifacta-classic/reference/transformation-reference.html) (read 2026-09-27)
- Trifacta: [`Logical Functions (group)`](https://help.alteryx.com/aac/en/trifacta-classic/wrangle-language/logical-functions.html) (read 2026-09-27)
- Trifacta: [`Logical Operators`](https://help.alteryx.com/aac/en/trifacta-classic/wrangle-language/logical-functions/logical-operators.html) (read 2026-09-27)
- Trifacta: [`Ternary Operators`](https://help.alteryx.com/aac/en/trifacta-classic/wrangle-language/other-functions/ternary-operators.html) (read 2026-09-27)
