Subform Aggregation (Numbers)
Subform aggregation lets you keep a running total, or average of a sub-form element and then display this total value on the parent form. Subforms can be set to allow for multiple paging, which creates an array of records. A built in function will sum, or average the same element over the entire array of records. Please see the following examples below to learn more about each function.
- iformbuilder.math.sum(array of records, element to perform the sum) - this will add the values you are bringing over to the parent from the array and display the sum of those values
- iformbuilder.math.avg(array of records, element to perform the average) - this will average the values you are bringing over to the parent from the array and display the average of those values.
Now to break the math function down into a digestible piece of information we must explain what each component of the function does.
The iformbuilder.math.sum function states that you want to add the values from all of the the subform records (the array) together. The next step is to pass the array of records we want to sum.
The array starts with the table name of the parent form where you will sum the records. You then need to reference the data_column_name of the sub-form element on the parent form. Finally, you need to reference the data_column_name of the element on the sub-form that will be summed. Below is an example of the syntax
This may be useful for a purchase order scenario where customers may be purchasing a number of items and you want to keep a running total of all items. Using subform aggregation would be the ideal way to set this form up.
Please watch the high definition video below, which walks you through a real life example of subform aggregation. Once you understand how this works you can modify the example to suit your specific needs.