Calculated Fields for ACF supports working with repeater fields (requires Advanced Custom Fields Pro) and group fields.
If a formula expression is added to a subfield inside a repeater or group field, any field name in the formula expression is assumed to be another subfield in the same repeater or subgroup.
Screenshot from a repeater field. Any formula expression in field "p1" or "p2" can refer to the "price" field. The same logic applies to group fields.
A formula expression in one of the subfields in a repeater or group field may refer to fields on the parent level using the prefix "parent" and a dot:
Assuming the parent level has a field named rebate.
On the parent level, the values in a repeater field can be accessed using one of the aggregation functions.
|sum()||The sum of the subfield for all rows in the repeater.|
|average()||The average of the subfield for all rows in the repeater.|
|count()||The count of rows in the repeater.|
|min()||The minimum value of the subfield for all rows in the repeater.|
|max()||The maximum value of the subfield for all rows in the repeater.|
An expression that sums up the values in subfield "price" for all rows in the repeater "orderlines"
To make the aggregation function work out, we’ve bent the normal rules of valid expressions a little bit. Anything after the dot (.) in the aggregate expression is an expression in itself that is evaluated for each row in the repeater. Therefore it’s perfectly OK to write a formula like:
This expression will walk over all lines in the “orderlines” repeater field, evaluate the expression “price * amount” and return the sum of all lines.
The side effect of this is that when working with aggregate functions, parentheses cannot be used in the expression. If you need to aggregate a more complex calculation, you should add an extra field in the repeater group and let the aggregate function work on this extra field.