Use the sum helper to add all numeric elements in an array field (e.g., record.items). To add multiple separate numeric fields or values, use the add helper instead. This helper can handle integers, floats, and numeric strings.
{{sum arrayField}}
- arrayField: A field containing an array of numbers. sum flattens nested arrays and adds all numeric elements. Non-numeric elements are skipped.
-
Summing an array of numbers
If
record.itemsis[2, 5, 7, 8, 9]:{{sum record.items}}produces
31. -
Summing a larger set of array elements
If
record.itemsis:[ 50, 10, 10, 10, 5, 5, 60, 10, 10, 10, 5, 5, 50, 10, 10, 10, 10 ]then
{{sum record.items}}returns290. -
Use add for separate fields
To add multiple separate fields or literal values, use the add helper instead:{{add record.tax record.shipping record.discount}}
Tip
- To add multiple separate values (e.g., {{add 5 10 20}}), use the add helper.
- When passing an array, non-numeric elements are skipped. Only numeric values (integers, floats, or numeric strings) are included in the total.
- Triple braces (
{{{ }}}) generally aren’t necessary unless you require the exact numeric output without any automatic formatting.