Expressions in Calculator
Expressions allow you to include the following elements:
- References to other fields of the input dataset (via field names) or other expressions previously computed in the same Calculator node (via expression names). To avoid errors, make sure the expression you are referencing appears higher than the current one in the expression list.
- References to variables on the input port. (Use the
Var.prefix to access input variables.)
Note: Names of fields, variables, and expressions are case-insensitive.
- Parentheses that define the order of operations
- Mathematical and relational operators
- Logical operators (
and,or,not, orxor) and values (true(1) andfalse(0)) - Functions as described in the syntax reference (see Function List)
- String expressions in double quotes (e.g.,
"string expression") - Integer and real numbers
- Single-line and multi-line comments
Note: Mathematical operations (such as addition or subtraction) on the
date/timedata may produce a real number with a fractional part. By default, the result equals the number of days (integer part) and the number of hours (fractional part). For example, the subtraction operation02.01.2020 12:00 - 01.01.2020 00:00returns1.5. The node will interpret it as one full day (24 hours) and 12 hours.
Caching
Enable caching in Calculator expressions when you use the Data() function for recursive value computation.
We also recommend to use caching with functions whose result depends on the time of computation, such as Random(), Today(), and similar functions.
Code pane toolbar
The code pane toolbar provides several commands for quick and convenient access.
Preview (F3): Use this button to display up to 100 rows of the result table for calculation check.
Console: Open this pane at the bottom of the Preview window to view errors found during expression evaluation. If there are no errors, the Console pane remains empty.
- Use the
Show and
Hide buttons on the top right to expand or collapse the Console pane.
- Use the
- Logical operators:
- AND: Logical AND
- OR: Logical OR
- NOT: Logical NOT
- XOR: Logical XOR (exclusive OR)
- Comparison operators:
- = (equal to)
- <> (not equal to)
- < (less than)
- > (greater than)
- <= (less than or equal to)
- >= (greater than or equal to)
- Templates:
Number: Enter a real number. (The command inserts
0.0into the expression code.)String: Enter a string value (inserts
"").Date: Enter a date (inserts
StrToDate("____-__-__", "YYYY-MM-DD")).Time: Enter a time value (inserts
StrToDate("__:__:__", "HH:NN:SS")).
- Logical values:
- FALSE: Insert
False - TRUE: Insert
True
- FALSE: Insert
Comments
The Calculator supports two types of comments:
- Single-line comment: Begin these with
//. The comment continues to the end of the line. - Multi-line comment: Begin these with
/*and end them with*/. The comment includes all the characters in between.
In the code area, use Ctrl + / to comment or uncomment code.
// Single-line comment example.
IF(IsNull(gate_one),gate_two,gate_one) // a single-line comment continues to the end of the line.
/* A multi-line comment
includes all characters
between slash-asterisk
and asterisk-slash. */
Read on: JavaScript Syntax in Calculator