An array field holds one row per item, so its value is a list rather than a single answer. A reducer expression reads every row in that array and returns one value: a total, a count, an average, an earliest or latest, or a single true or false.
Reducers live in the category of the value they return, not in the Array category. A total of integers is an Integer expression, an all-rows-true check is a Boolean expression, and a total duration is a Duration expression. The Array Expressions page holds only the expressions that return an array.
Totalling a value across every row
This procedure adds up one numeric field from every row of an array and writes the total into a separate field. Start with a form that already has an array field with a numeric field inside it, and a second numeric field to hold the result. You are finished when the result field shows a running total that changes as rows are added.
Select the field that will hold the total.
Click the sigma icon in the right rail to open Calculation properties.
Set Update to
calculation. The Calc Editor opens.Type the reducer’s name in the Search Integer Expressions box, then drag it onto Drag and Drop an Integer Expression or a Form Field Here.
The block appears with two parameters.
arraynames the array to read, and the second parameter names the value to evaluate for each row.Turn on Show All Expressions, search for
field, and scroll to the Array category.Drag that category’s Field entry onto the
arrayparameter’s box.Click the magnifier in the box that appears, choose your array field, and click OK.
Repeat the last three steps for the second parameter, using the category that matches its type, and choose the field inside the array’s row.
Click OK.
Drop below the parameter name, not on it
A drop that lands on a parameter’s label does nothing. No error appears and the parameter stays unset. Aim for the box underneath the name.
The stored expression names both parameters:
{ "sum-array-integers": { "array": { "field": "itemList" }, "integer": { "field": "itemQty" } } }Watching a reducer recalculate
Reducers recalculate as soon as the array changes. Adding a row, deleting a row, or editing any value the reducer reads all trigger it. No save or workflow transition is needed.
An untouched row is not a false row
A per-row boolean nobody has touched is unset, and unset is not the same as false. And-Array-Booleans skips unset rows, so an all-items-done check reports true while rows are still untouched. It turns false only once a row holds an explicit false. Give every per-row boolean an initial value of false, or a completion check passes on rows the user has never opened.
Choosing between a count and a position
Count-In-Array returns how many rows match a filter. Position-In-Array returns where the first matching row sits. Use the count when you need a quantity, and the position when you need to reach back into a specific row.
Expression reference
Reducers that return a number, on the Decimal and Integer Expressions page:
Expression | What it does |
|---|---|
| The total of integers from within an array. |
| The total of decimals from within an array. |
| The average of decimals from within an array. |
| The largest or smallest value from within an array. |
| The number of items in an array where the filter is true. |
| The number of 'true' results in a list. |
| The position of the first item in an array where the filter is true. |
| The number of rows in an array. |
Reducers that return a boolean, on the Boolean Expressions page:
Expression | What it does |
|---|---|
| The AND result of booleans from within an array. |
| The OR result of booleans from within an array. |
| The exclusive-or result of booleans from within an array. |
Reducers that return a date, time, or duration, on the Date/Time and Duration Expressions page:
Expression | What it does |
|---|---|
| The total duration across an array column. |
| The mean duration across an array column. |
| The latest or earliest date/time across an array column. |
| The longest or shortest duration across an array column. |