Articles in this section

sum helper

Use the sum helper to add multiple numeric values or all elements of an array. It accepts either an array from a field (e.g., record.items) or one or more individual numeric fields/values. This can handle integers, floats, and numeric strings.

Usage

{{sum field1 field2 field3}}
  • fieldX: One or more fields or variables containing numeric data. If a single argument is an array, sum processes each element. If multiple arguments are passed, sum adds them all together.

Examples

  1. Summing an array of numbers 

    If record.items is [2, 5, 7, 8, 9]:

    {{sum record.items}}

    produces 31.

  2. Summing a larger set of array elements 

    If record.items is:

    [  50, 10, 10, 10, 5, 5,  60, 10, 10, 10, 5, 5,  50, 10, 10, 10, 10 ]

    then {{sum record.items}} returns 290.

  3. Adding numeric fields together 

    {{sum record.tax record.shipping record.discount}}

    This calculates the sum of three numeric fields within record.

  4. Using expressions for intermediate calculations 

    {{sum (multiply 2 55)}}

    Here, the helper sums the result of (multiply 2 55), which is 110.

Tip

  • If you pass multiple arguments (e.g., {{sum 5 10 20}}), sum adds all of them and returns the total.

  • When passing a single array, ensure all elements are valid numbers; otherwise, the helper might skip or misinterpret them.

  • Triple braces ({{{ }}}) generally aren’t necessary unless you require the exact numeric output without any automatic formatting.