data management
slug: step-calculateCreates new calculated fields or transforms existing ones using either direct assignments or conditional logic. Safely evaluates expressions to derive new data points from existing values.
At least one of:
assign (object) - Map of field names to expressions/valuescase (object) - Map of field names to conditional rulesstrict_mode (boolean) - When true, throws exceptions for failed expressions. Default: false"fieldName": 123"status": "Active""total": "$price * $quantity""fullName": "trim($firstName . ' ' . $lastName)"Structure for each field:
"fieldName": [
{"when": "condition1", "then": "value1"},
{"when": "condition2", "then": "value2"},
{"else": "defaultValue"}
]
else clause provides a default valueAdds metadata for new fields including:
name - Field nametype - Detected data type (N for numeric, C for character)length - Estimated field lengthformat - Default null (can be updated later)label - Same as field namesource - Set to 'calculated'calculate_applied - Timestamp when calculation was performedfields_calculated - Number of fields added to PDVassign_processed - Number of assign operations performedcase_processed - Number of case operations performedcalculate:
assign:
total: "$price * $quantity"
discount: "$total * 0.1"
netTotal: "$total - $discount"
timestamp: "date('Y-m-d H:i:s')"
case:
priceTier:
- {when: "$price < 10", then: "Low"}
- {when: "$price < 50", then: "Medium"}
- {when: "$price >= 50", then: "Premium"}
shippingClass:
- {when: "$weight > 20", then: "Heavy"}
- {when: "$fragile == true", then: "Careful"}
- {else: "Standard"}
strict_mode: true
| id | price | quantity | weight | fragile |
|---|---|---|---|---|
| 1 | 45 | 2 | 15 | false |
| 2 | 8.99 | 3 | 25 | true |
| id | price | quantity | weight | fragile | total | discount | netTotal | timestamp | priceTier | shippingClass |
|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 45 | 2 | 15 | false | 90 | 9 | 81 | 2024-10-24 12:30:15 | Medium | Standard |
| 2 | 8.99 | 3 | 25 | true | 26.97 | 2.697 | 24.273 | 2024-10-24 12:30:15 | Low | Careful |