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.
Before you begin
Ensure you have access to the data model you want to enhance with a computed column.
Navigate to the data model
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).
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();
}
}
You will need to save the computed column's configuration to apply your changes to the data model.
Finish line
By now, you have successfully set up a computed column in Cargo, you can now use the computed column in your workflows.