User Tools

Site Tools


transformations:rule

RULE

Category: Transform / Basic


Description

This action calculates a new column or replaces an existing column, by using one or several ordered IF…THEN…ELSE conditions. The conditions are checked one by one until a satisfying condition is found. When found, the result is calculated and all other conditions are ignored. When no satisfying condition is found, the default calculation is applied.


Action settings

Column options

SettingDescription
Create new columnThis option creates a new column with the results of the rule. Enter a name for the new column in the text box at the right.
Replace existingWith this option, select the column that will contain the results of the rule, overwriting the existing values.


Calculated as settings

SettingDescription
ifAn expression that evaluates to either TRUE or FALSE which determines whether the then statement will be processed (i.e., the then will run when the if expression is TRUE.
thenThe value inserted into the column when the if condition is TRUE. This can be entered as an expression or static value. Options: this is an expression or this is a text or number.

You can add more if/then conditions using the Add more rules option. An else will be inserted between if/then pairs, indicating that later conditions are only run if previous conditions evaluate to FALSE. The if/then rules are evaluated in the order entered until one evaluates to TRUE, and the rest are ignored.

No conditions met options

SettingDescription
Make emptyIf none of the if statements evaluate to TRUE, enter an "empty" value.
Default toOptions: it's an expression or it's a text or number. Enter either an expression to be evaluated or a static value,
in cases where none of the if statements evaluate to TRUE.
Keep original valueIf none of the if statements evaluate to TRUE, retain the original value.


Remarks

The order of conditions is significant as conditions are checked starting with the first (top). Therefore, conditions that come first have priority over conditions that come later.

While the same result can be achieved using an expression with nested if functions, the use of Rule action is recommended for clarity, readability, and the ease of rearranging the order.

This action doesn't evaluate expressions that shouldn't be evaluated because the condition is or is not true. For example, it can be used with the columnexists() function to perform calculations with columns that are not guaranteed to exist.


Examples

Example #1

Add a column that flags countries' Disposable income as "LOW" if 30,000 or below.

Before (source table)

Country Gross Disposable
United States 56067 45582
Australia 51050 32617
Switzerland 53716 48414
Canada 45896 27469

After (result table)

Country Gross Disposable Low flag
United States 56067 45582
Australia 51050 32617
Switzerland 53716 48414
Canada 45896 27469LOW

Action parameters:

Create new column: Low flag
Calculated as:
if ([Disposable] ⇐ 30000), then LOW
If none of the conditions above is met: Default to ""


Community examples


Shortcuts

Fast ways to create the action:

  • Right-click on a column heading, and select "Modify", then "With rule…" from the submenu.
  • Click the drop-down arrow in a column heading and select "Modify", then "With rule…" from the submenu.


See also

transformations/rule.txt · Last modified: 2025/01/13 16:28 by craigt

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki