Skip to main content

Calc Editor: Aggregating Array Data

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.

Step-by-step
  1. Select the field that will hold the total.

  2. Click the sigma icon in the right rail to open Calculation properties.

  3. Set Update to calculation. The Calc Editor opens.

  4. 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.

  5. The block appears with two parameters. array names the array to read, and the second parameter names the value to evaluate for each row.

  6. Turn on Show All Expressions, search for field, and scroll to the Array category.

  7. Drag that category’s Field entry onto the array parameter’s box.

  8. Click the magnifier in the box that appears, choose your array field, and click OK.

  9. 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.

  10. 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

Sum-Array-Integers

The total of integers from within an array.

Sum-Array-Decimals

The total of decimals from within an array.

Average-Array-Decimals

The average of decimals from within an array.

Max-Array, Min-Array

The largest or smallest value from within an array.

Count-In-Array

The number of items in an array where the filter is true.

Count-Where-True

The number of 'true' results in a list.

Position-In-Array

The position of the first item in an array where the filter is true.

Length-Array

The number of rows in an array.

Reducers that return a boolean, on the Boolean Expressions page:

Expression

What it does

And-Array-Booleans

The AND result of booleans from within an array.

Or-Array-Booleans

The OR result of booleans from within an array.

Xor-Array-Booleans

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

Sum-Array-Durations

The total duration across an array column.

Average-Array-Durations

The mean duration across an array column.

Max-Array, Min-Array

The latest or earliest date/time across an array column.

Max-Array, Min-Array

The longest or shortest duration across an array column.