Formula syntax
Datagrok uses a unified formula syntax across the platform for calculated columns, filters, and other expressions.
Referencing data in formulas
Current row value
Use ${ColumnName} to reference the value in the current row.
This is the most common case, when a formula is evaluated independently for each row.
The same syntax is used when passing a column to functions that process all values at once and return a result for each row, such as formula equalities.
${AGE} > 18
${PRICE} * ${QUANTITY}
${Chemical Space Y} = ln(${Chemical Space X}) + 5 // formula line equality
Entire column
Use $[ColumnName] to reference all values in a column at once. This is used when the formula needs column-level information, such as averages, totals, or other aggregated values.
${IC50} / Avg($[IC50])
${VALUE} > Median($[VALUE])
Row index
Use row when the formula explicitly requires the row index.
row % 2 == 0
Operators, constants, and literals
Operators
Datagrok supports arithmetic, comparison, logical, and membership operators.
You can use them with numbers, logical values (true, false), constants like PI and E, function results, or current row values ${ColumnName}.
You can combine operators and functions to build complex expressions.
Use parentheses () to control the order of evaluation.
Sin(PI / 6) * (17 - ${LENGTH}) < 9 // The result is a boolean value
Each operator also has a corresponding function, so you can choose whichever form is more convenient.
Reference: list of operators
Here A is the left operand of the operator and the B is the right operand.
| Operator | Description | Similar Function |
|---|---|---|
/ | The result of dividing A by B | Div(A, B) |
* | The product of A and B | Mul(A, B) |
% | The remainder of dividing A by B | Mod(A, B) |
^ | Returns A to the power of B | Pow(A, B) |
+ | The sum of two numbers A and B | Add(A, B) |
- | The difference between A and B | Sub(A, B) |
== | True if A equal to B and false otherwise | Eq(A, B) |
!= | False if A equal to B and true otherwise | NotEq(A, B) |
> | True if A is greater than B and false otherwise | Greater(A, B) |
< | True if A is less than B and false otherwise | Smaller(A, B) |
>= | True if A is greater than or equal to B and false otherwise | NotSmaller(A, B) |
\<= | True if A is less than or equal to B and false otherwise | NotGreater(A, B) |
and | Logical conjunction of boolean A and B | And(A, B) |
&& | Logical conjunction of boolean A and B | And(A, B) |
or | Logical disjunction of boolean A and B | Or(A, B) |
xor | Logical exclusive disjunction of boolean A and B | Xor(A, B) |
not | Logical negation of the B | Not(B) |
! | Logical negation of the B | Not(B) |
in | In operator, A in [A,B] returns true | In(A, B) |
Constants
Datagrok provides predefined constants that you can use in formulas by simply writing their names.
E * ln(${VALUE}) / SQRT2
Reference: list of constants
- Common
- Other mathematical
- Chemical and physical
| Name | Description | Value |
|---|---|---|
E | Euler's number | 2.718281828459045 |
LN2 | Natural logarithm of 2 | 0.6931471805599453 |
LN10 | Natural logarithm of 10 | 2.302585092994046 |
LOG2E | Base-2 logarithm of E | 1.4426950408889634 |
LOG10E | Base-10 logarithm of E | 0.4342944819032518 |
PI | Pi | 3.1415926535897932 |
SQRT1_2 | Square root of 1/2 | 0.7071067811865476 |
SQRT2 | Square root of 2 | 1.4142135623730951 |
| Name | Description | Value |
|---|---|---|
APERY | Apéry's constant | 1.202056903159594 |
BACKH | Backhouse's constant | 1.456074948582689 |
BERN | Bernstein's constant | 0.280169499023869 |
CATALAN | Catalan's constant | 0.915965594177219 |
CONWAY | Conway's constant | 1.303577269034296 |
EUMA | Euler–Mascheroni constant | 0.577215664901532 |
ERDBOR | Erdős–Borwein constant | 1.606695152415291 |
FEIG1 | Feigenbaum constant 1 | 4.669201609102990 |
FEIG2 | Feigenbaum constant 2 | 2.502907875095892 |
FHL | First Hardy–Littlewood conjecture | 0.660161815846869 |
FROB | Fransén–Robinson constant | 2.807770242028519 |
GAKUWI | Gauss–Kuzmin–Wirsing operator | 0.303663002898732 |
GODI | Golomb–Dickman constant | 0.624329988543550 |
GRATIO | Golden ratio | 1.6180339887498948 |
HASAMC | Hafner–Sarnak–McCurley constant | 0.353236371854995 |
KHIN | Khinchin's constant | 2.685452001065306 |
LANRAM | Landau–Ramanujan constant | 0.764223653589220 |
LEVY | Lévy's constant | 3.275822918721811 |
MEME | Meissel–Mertens constant | 0.261497212847642 |
MILLS | Mills' constant | 1.306377883863080 |
NIVEN | Niven's constant | 1.705211140105367 |
OMEGA | Omega constant | 0.567143290409783 |
PLASTIC | Plastic constant | 1.324717957244746 |
RAMSOL | Ramanujan–Soldner constant | 1.451369234883381 |
RECFIB | Reciprocal Fibonacci constant | 3.359885666243177 |
SIERP | Sierpiński's constant | 2.584981759579253 |
SQRT3 | Square root of 3 | 1.732050807568877 |
SQRT5 | Square root of 5 | 2.236067977499789 |
UNIPAR | Universal parabolic constant | 2.295587149392638 |
| Name | Description | Value |
|---|---|---|
AVOGADRO | Avogadro's Number | 6.02214e+23 |
FARADAY | Faraday Constant | 96485.33 (C·mol-1) |
ATOM | Atomic Mass Constant | 1.66053906660e-27 (kg) |
GAS | Molar Gas Constant | 8.31446261815324 (m3⋅Pa⋅K−1⋅mol−1) |
COULOMB | Coulomb constant | 8.9875517923e+9 (N·m2/C2) |
MAXSPEED | Speed of Light (Vacuum) | 299792458 (m/s) |
BOLTZ | Boltzmann constant | 1.380649e-23 (J⋅K−1) |
ECHARGE | Elementary charge | 1.602176634e-19 (C) |
GRAVITY | Standard gravity | 9.80665 (m/s2) |
PLANCK | Planck constant | 6.62607004e-34 (J⋅Hz−1) |
EMASS | Mass of electron | 9.1093837015e-31 (kg) |
NMASS | Mass of neutron | 1.67492749804e-27 (kg) |
PMASS | Mass of proton | 1.67262192369e-27 (kg) |
String literals
String values can be written using single or double quotes. Both forms are supported and interchangeable.
'Medium'
"Medium"
Whitespace and line breaks
Spaces around operators are optional, and formulas can include line breaks. Whitespace and formatting do not affect how formulas are evaluated.
The following examples are valid and equivalent:
${A}+${B}
${A} + ${B}
${A}
+
${B}
in(20,60,40)
in(20, 60, 40)
Functions
Built-in functions
Datagrok provides built-in functions, including calculations, text manipulation, statistical analysis, date/time operations, conversions, binning, and timespan operations.
RoundFloat(${IC50} / Median($[IC50]) * E, 3)
Custom functions
Datagrok allows you to create custom functions in Python, R, Julia, JavaScript, C++, and other languages, as long as they are properly annotated.
See Function annotations for details.
Functions can be written as standalone scripts or included in packages.
Package function
Use PackageName:FunctionName to call package function.
Chem:getInchis(${Structure})
User-defined function
Use UserLogin:FunctionName to call user-defined function.
The following example shows a custom function written in Python:
#name: Len
#language: python
#input: string s
#output: int length
length = len(s)
Once the script is saved, the function can be called in formulas like this:
UserName:Len(${ColumnName})
Calculated columns
Calculated columns generate new columns based on formulas. They can reference other calculated columns and update automatically when the source data changes.
The Add New Column dialog supports creating calculated columns with real-time preview, autocomplete, and formula validation, including checks for syntax errors, missing columns, and type mismatches.
See Add New Column for details.
In-viewer filter expressions can be edited in the Edit Formula dialog, which provides the same enhanced functionality as Add New Column.
Complex calculated columns (multiple outputs)
In some cases, a single formula can produce multiple columns at once. This is useful when a function returns several related results that should stay synchronized with the source data. When used from Add New Column, all resulting columns are created automatically and remain synchronized with the source data.
For details, see Сomplex calculated columns.