A reference to a child field in a repeatable section, such as ${field.POItems.Quantity} can mean either a single row's value or the whole column. Which one it means, and therefore which operators can be used, depends on where the rule writes its result.
When the result is written to a field inside the repeatable section, the rule runs once for each row, and each reference is that row's single value. All operators work as they would for any other calculated field case, including * and /.
When the result is written to a field outside the repeatable section, each reference is the whole column rather than a single value. In this case:
- + and - still work row by row.
- * and / still work when the other side is a single value, such as a number, a field outside the section, or a form variable. For example, =sum(${field.POItems.Amount} * ${variable.TaxRate}).
- * and / must not be used between two columns, because multiplication between two columns is a matrix operation rather than a row-by-row one. Use dotMultiply and dotDivide instead.
For example, a PO Items repeatable section contains Quantity, Unit Price, and a read-only Line Total field. Because the Line Total field is inside the section, the following formula multiplies each row's quantity and unit price and writes the result to that row:
=${field.POItems.Quantity} * ${field.POItems.UnitPrice}
To display the total of all line items in a field outside the repeatable section, use:
=sum(${field.POItems.LineTotal})
To calculate the same total without a Line Total field, multiply the two columns with dotMultiply. The target is outside the section, so * cannot be used here:
=sum(dotMultiply(${field.POItems.Quantity}, ${field.POItems.UnitPrice}))
To display the number of rows, use:
=rowCount(${field.POItems})
You can use aggregate calculations with form rules to calculate a value from all rows in a repeating section. Aggregate calculations update when a form user adds, changes, or removes a row.
Aggregate calculations use the following syntax FUNCTION(RepeatingSectionID.WidgetID), where:
- FUNCTION is the applied aggregate function
- RepeatingSectionID is the identifier of the repeating section that contains the values that will be used for the calculation
- FieldID is the identifier of the widget whose values will be used for the calculation. The supported field types are Number and Currency
The following functions are available for calculations across repeatable sections:
| Function | Description | |
|---|---|---|
| sum(values) | Adds the values from all applicable rows. | =sum(${field.POItems.LineTotal}) |
| count(values) | Counts the values in a collection. When passed an entire section, it counts cells rather than rows. | =count(${field.POItems.UnitPrice}) |
| rowCount(section) | Returns the number of rows in a repeatable section. | =rowCount(${field.POItems}) |
| min(values) | Returns the lowest value from all applicable rows. | =min(${field.POItems.UnitPrice}) |
| max(values) | Returns the highest value from all applicable rows. | =max(${field.POItems.UnitPrice}) |
| mean(values) | Calculates the average of the values from all applicable rows. | =mean(${field.POItems.UnitPrice}) |
| std(values) | Calculates the standard deviation of values across all applicable rows. Standard deviation indicates how widely the values are distributed around the mean. | =std(${field.POItems.UnitPrice}) |
| median(values) | Returns the median (middle) value when all values are sorted in ascending order. | =median(${field.POItems.UnitPrice}) |
| mad(values) | Returns the median absolute deviation. | =mad(${field.POItems.UnitPrice}) |
| dotMultiply(left, right) | Multiplies corresponding values in two columns. Required instead of * when the result is written outside the section. | =sum(dotMultiply(${field.POItems.Quantity}, ${field.POItems.UnitPrice})) |
| dotDivide(left, right) | Divides corresponding values in two columns. Required instead of / when the result is written outside the section. | =mean(dotDivide(${field.POItems.Total}, ${field.POItems.Quantity})) |