Calculated Field #
While working with a Workflow, you may want to add a new column that is the result of a calculation from other columns. Below we present avaliable options for you to do so.
Script #
You can add a Calculated Field using a Script Component (most often a Script Transformation).
Because only database sources return data tables with correct data types, make sure the columns used for calculation are eitherIntegers
orFloats
before creating a Calculated Field this way.
Example Table
Product | Sell Price (USD) | Production Cost (USD) |
---|---|---|
Margherita Pizza | 8.99 | 3.56 |
Spaghetti Bolognese | 9.99 | 4.76 |
Tomato Soup | 4.99 | 0.89 |
Pancakes with Strawberry Jam | 5.49 | 2.50 |
Example Script Transformation
import pandas as pd
df = INPUT_DATA[0]
if df.empty:
df['Profit'] = 1.1
else:
df['Profit'] = df['Sell Price (USD)'] - df['Production Cost (USD)']
OUTPUT_DATA = df
The result data table would look as follows:
Product | Sell Price (USD) | Production Cost (USD) | Profit |
---|---|---|---|
Margherita Pizza | 8.99 | 3.56 | 5.43 |
Spaghetti Bolognese | 9.99 | 4.76 | 5.23 |
Tomato Soup | 4.99 | 0.89 | 4.1 |
Pancakes with Strawberry Jam | 5.49 | 2.50 | 2.99 |