Create a computed column inside a data model

In this tutorial, we will guide you through the process of creating a computed column in Cargo.

Computed columns allow you to use expressions, or embedded code, to dynamically generate data based on existing fields.


Pre-requisites

Before you begin

Ensure you have access to the data model you want to enhance with a computed column.


Step 1

Click on the right pane of your data model and proceed to the Columns tab.


Click the Add button to create a new computed column.

Choose the data type for your computed column based on the kind of data you want to generate (e.g., String, Number, Boolean).



Step 2

Define the expression

Add an expression to define the formula for your computed column. This expression will determine how the column's values are computed based on existing fields in your data model.

For more complex expressions, refer to the tutorial on understanding the cargo expressions template.


For instance, concatenate string values from two columns:

Concatenate first and last name of a record

{{ record.firstName }} {{ record.lastName }}

You can also use more complex javascript expressions to calculate values. For example, calculate age from date of birth:

Calculate age from date of birth

{
  {
    new Date().getFullYear() - new Date(record.birthDate).getFullYear();
  }
}


Step 3

Save the model

Click Save to apply new computed column's configuration.


You will need to save the computed column's configuration to apply your changes to the data model.


Outcome

Finish line

By now, you have successfully set up a computed column in Cargo, you can now use the computed column in your workflows.