User Tools

Site Tools


syntax:start

Expressions

In EasyMorph you can use expressions to calculate new columns or build complex conditions for filtering table rows. An expression is calculated for every row of a table and can include:

Field names

You can refer to values in columns of the table where the expression is calculated by putting column names in square brackets, e.g. [Amount]. Field names can include spaces, digits and non-alphabetical characters in any order.

When expression is calculated for a row, field names are replaced with values in these fields stored in the row. It's not possible to refer to values from another row or another table.

Field names are case sensitive – i.e. [Total], [TOTAL] and [total] are 3 different field names.

Parameters

An expression can refer to project parameters that are evaluated to text or number constants prior to calculating the expression. Parameter names in expressions are wrapped in curly brackets and are case-sensitive. E.g. {File name}, {Ratio}.

Comments

Expressions can be annotated (commented). Any text between a double-slash (//) and the end of line is considered a comment and is ignored during expression evaluation. A comment can't span several lines. Example:

//Converted amount.
[Amount] * {FX Rate}  // Using a parameter for the exchange rate.

Example 1

Let's assume we want to calculate new field 'Net Amount' using the following expression:

[Price] * [Quantity] * ( 100 - [Discount %] ) / 100

Resulting table:

Price Quantity Discount % Net Amount
100 5 10 450
120 6 15 612
120 20 20 1920

Example 2

Let's assume we want to calculate new field 'Total Tax' using the following expression:

[Amount] * if( [Province]='QC', 13.5, 12.5) / 100 * {Multiplier}

Where parameter {Multiplier} is 1.

Resulting table:

Province Amount Total Tax
ON 1000 125
BC 1500 187.5
QC 2000 270

A few transformations that use expressions

syntax/start.txt · Last modified: 2021/07/21 15:22 by dmitry

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki