ETLMCPData Conveyance Works
Log in Start free
Docs

Expression syntax for filter and derive

What you can write in a filter or derive expression: numbers, field names, arithmetic, comparisons, and/or/not, and how text and blanks behave.

A filter or derive expression is a small formula over one row. You can write numbers, field names such as cost or extra.actions.purchase, the operators + - * / % ** and parentheses, the comparisons > < >= <= == !=, the words and, or and not, and true or false. A filter keeps a row when its expression comes out true; a derive writes the expression's result into the column it names. There are no quoted words in the syntax, and an expression may be at most 2000 characters long.

The parts of an expression

  • Numbers. Whole numbers and decimals: 100, 2.5, .5. There is no thousands separator and no scientific notation.
  • Field names. A name starts with a letter or an underscore and goes on with letters, digits and underscores. Dots join parts, which is how you reach the platform columns kept under extra: extra.reach, extra.actions.purchase. A row that has no value for an extra. name reads it as blank rather than failing.
  • Arithmetic. + adds, - subtracts, * multiplies, / divides, % gives the remainder and ** raises to a power. A leading - makes a value negative.
  • Parentheses. Group any part: (conversion_value - cost) / cost.
  • Comparisons. >, <, >=, <=, == (equal) and != (not equal).
  • Logic. and, or and not, written in lowercase.
  • True and false. true and false, in lowercase or with a capital first letter.
  • Functions. abs, min, max, round, floor, ceil, ln, log10 and sqrt, called with their arguments in parentheses: round(cost / clicks, 2).

Equal is two signs

Write equality as ==. A single = inside an expression is refused when you save: cost = 0 fails with trailing tokens in expression at {…}. In the dashboard's rule editor, a derive line does use one =, but outside the expression: in roas = conversion_value / cost, the column name sits to the left of the sign and the expression to the right. See the derive rule.

Which operator goes first

Operators bind in the usual arithmetic order, from tightest to loosest:

  1. **
  2. a leading - or +
  3. *, / and %
  4. + and -
  5. one comparison
  6. not
  7. and
  8. or

So 2 + 3 * 4 is 14 and -2 ** 2 is -4. An expression holds one comparison at a time: 0 < cpc < 2 is refused, so write cpc > 0 and cpc < 2. not cost > 5 reads as "not (cost > 5)".

Which names you can use

When you save a rule, or try it in the Trial Run of the Rules on the pipeline page, etlmcp checks the expression against a fixed set of names: date, currency, impressions, clicks, cost, conversions, conversion_value, ctr, cpc, cpm and cpa, plus any name that starts with extra.. Any other name is refused with unknown field {…}, for example unknown field 'campaign_name'. That includes a column an earlier rule created or renamed: a derive that makes roas followed by a filter on roas > 2 is refused, so write the formula out in the filter instead (conversion_value / cost > 2).

Text in an expression

date and currency hold text, and so can an extra. column. You can join two pieces of text with +, as in date + currency, up to a length limit; a longer result fails with text result is too long. Other arithmetic with text fails: -, %, or + between text and a number gives cannot calculate with text, * gives cannot multiply text, and dividing text by a number other than zero fails as well.

You cannot type a word in quotes. currency == 'USD' is refused with bad token at {…} in {…}, because quote marks are not part of the syntax. You can still compare two fields that hold text, such as == between two columns.

Blanks and division by zero

A field with no value on a row behaves like this:

Where the blank is Result
In + or - it counts as 0
Dividing by zero or by a blank, or % by zero or a blank the result is blank
In a comparison the comparison is false
In * or **, or as the number being divided by / or % the expression fails for that row

Because a comparison with a blank is false, a filter such as extra.reach > 1000 drops every row without a reach value, and not extra.reach > 1000 keeps them.

When an expression fails on a row

etlmcp checks each expression's syntax when you save the rules, and the save fails with the message. Some problems only show up on real rows, such as text in an extra. column or the square root of a negative number. Then:

  • Derive: the column is left blank on that row, and the run goes on.
  • Filter: a row whose expression cannot be worked out is dropped. An error etlmcp raises itself, such as cannot calculate with text or cannot multiply text, stops the run instead, and the run is not tried again by itself (see retries).

Limits

  • An expression may be at most 2000 characters. A longer one fails with expression is too long (max 2000 characters). The rule box in the dashboard's editor takes a shorter line than that, so there a rule's text stops before this limit.
  • A pipeline's transform holds at most 50 rules.
  • Powers, rounding digits and nesting depth are also bounded.

When a save is refused, the message starts with the rule's kind and its position, counted from 0: filter (rule 0): unknown field 'clicksx'. The transform errors page lists the messages.

Related