An expression in a derive or filter rule can call nine functions and no others: abs, min, max, round(x[, digits]), floor, ceil, ln, log10 and sqrt. Function names are lowercase and must match exactly. Any other name, including ROUND in capitals or a function you know from a spreadsheet such as if, is refused with unknown function {…}, where the braces hold the name you typed. etlmcp shows that message when you save the pipeline or preview its transform, before any data runs.
The nine functions
| Function | What it returns | Example and result |
|---|---|---|
abs(x) |
x without its sign |
abs(conversion_value - cost) gives the gap whichever is larger |
min(a, b, ...) |
the smallest of two or more values | min(cost, clicks, 3) with cost 10 and clicks 4 gives 3 |
max(a, b, ...) |
the largest of two or more values | max(cost, 0) never goes below zero |
round(x) |
x rounded to a whole number |
round(3.5) gives 4 |
round(x, digits) |
x rounded to that many decimal places |
round(1234.5678, 2) gives 1234.57 |
floor(x) |
the whole number at or below x |
floor(-1.5) gives -2 |
ceil(x) |
the whole number at or above x |
ceil(1.2) gives 2 |
ln(x) |
the natural logarithm of x |
ln(1) gives 0 |
log10(x) |
the base-10 logarithm of x |
log10(1000) gives 3 |
sqrt(x) |
the square root of x |
sqrt(16) gives 4 |
How to write a call
Write the name, then the arguments in parentheses, separated by commas. Each argument is arithmetic: field names, numbers, + - * / % **, parentheses and other function calls. An argument cannot be a bare comparison or an and/or, so write max(cost, clicks) > 1; max(cost > 1, clicks) is refused. Calls nest, so round(max(cost, 0) / clicks, 2) is a valid cost per click to two places.
min and max need at least two arguments. With one, such as min(cost), the rule is refused with a message ending cannot evaluate: {…}.
How round behaves
Without digits, round returns a whole number. A value exactly halfway rounds to the even neighbour: round(2.5) gives 2, round(3.5) gives 4 and round(-2.5) gives -2. Some decimals cannot be stored exactly, so round(2.675, 2) gives 2.67, not 2.68.
A negative digits rounds to the left of the decimal point: round(1234, -2) gives 1200. digits must be a whole number within a fixed range either side of zero. A fraction such as round(cost, 1.5) or a value past that range is refused with round takes -{…} to {…} digits, which names the range.
When a function cannot give a value
ln of zero or of a negative number, sqrt of a negative number, and any function given an empty value have no answer. Division by zero in etlmcp gives an empty value, so round(cost / clicks, 2) has no answer on a row with no clicks. What happens next depends on the rule:
- In a derive rule, the new column is left empty on that row, and the run goes on.
- In a filter rule, the row is dropped and counted with the other dropped rows.
The check that runs when you save or preview evaluates each expression once, with the standard metrics set to 1 (the ratio columns ctr, cpc, cpm and cpa to 0.1) and every extra. field to 1. An expression that has no answer on those values is refused with cannot evaluate: {…}. For example, ln(cost - 1) takes the logarithm of zero there, so it cannot be saved, even though it would work on most real rows.
What the list leaves out
There is no if, no text function and no date function. A function cannot fill an empty value with a default, but + and - count an empty value as zero, so extra.video_views + 0 gives 0 on a row without that field. To set a floor or a ceiling, use max or min. To leave out rows a calculation does not suit, put a filter rule before the derive rule. One expression can be at most 2000 characters long, and one transform can hold at most 50 rules.
For the rule that uses these functions most, see the derive rule. For the other messages a transform can be refused with, see transform validation errors.