Model Basics – Calculated Column

Calculated columns make use of a powerful math engine that enables equations to be applied to a column of information. Multiple data and information types can be used and for each, multiple functions are available.

To illustrate some of the capabilities of this math engine, lets start with an example table of random information of various kinds:

Right click in the table, and select ‘Add Calculated Column’ under Table Functions:

This results in a popup where we enter the formula. Note the preview table below has a new ‘Calculated Column’ at the end that shows the result of the simple formula we provided: '1 - "Percent":

After clicking on ‘OK’ a new model is created showing the result:

Here are more examples of operations on other columns:

Formula & NotesSample Output
concat("Text", ' ~ ',"Text 2")

This example shows one of many string functions that are available
"Text".toUpperCase()

Many javascript functions are available to apply to values. There are over 20 native string functions that can be applied like this.
concat(string(1+"Date".getMonth()), ' / ', string("Date".getFullYear()))

This example combines a few things. The date functions getMonth and getFullYear return a number. The concat function only works with strings, so the string() function converts them. Also the getMonth date function returns a number from 0 to 11, so 1 needs to be added. There are about 30 date functions available for use.
complex("Number","Number 2") / 10 + 3 + 4i

This example shows the math engine operating on complex numbers
unit("Number", 'in') + unit("Number 2", 'cm') to ft

The math engine understands units and so provides a convenient way to perform calculations on measured numbers. Units of length, area, volume, angles, time, mass, temperature, energy, pressure, electricity and magnetism are all available.
Here the calculation is to take ‘Number’ as inches, ‘Number2’ as centimeters, add them and show the result in feet.
"Color".blend("Color 2", 0.5)

About 50 color functions are available. This one blends 50% of "Color 2" with "Color".
"Currency">"Currency 2"?"Text":"Text 2"

This is an example of a conditional or ternary operator, essentially executing an if .. then .. else operation. The expression before the ‘?‘ needs to return a boolean condition. If true the value before the : is used, else the value after is used.

Complex filter operations can be applied this way, where the expression calculates one of two values, that can be filtered in the model in a later step.

To expand on the last idea – lets say we wanted to find all instances where the columns "Percent" and "Percent 2" were within 0.02 of each other. Then we could enter a calculated column as follows:

The formula used is: abs("Percent"-"Percent 2") < 0.02

The function abs provides the absolute value. In this example we also change the column type to boolean.

This adds a new step to the model. From this step we can add a filter that filters only on the value we selected. (Here we’ve selected a row where the calculated column shows as true).

This also adds a new step to the model, showing the filtered results:

This post has provided an overview of some of the very many features of the calculated column model step.

Back to Exploring

trudain.com | All content copyright (c) 2022-2024