Here's what you need to know:
- What are Subforms?
- What is Subform Aggregation?
- What is the iformbuilder.math.sum function?
- What is the iformbuilder.math.avg function?
- How do I aggregate Subform data?
- Download Subform Aggregation Form Package
What is a subform?
Subforms can be used to create sub-sections of a larger form. Subforms should take form elements that would originally be on the Parent Form and add them to a separate form that will be linked to the Parent Form.
Subforms can be configured to allow for multiple subform records to be created.
What is Subform Aggregation?
Subform Aggregation lets you keep a running total, or an average (depending on the function) 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. The built-in function will sum or average the same element over the entire array of records.
What is the iformbuilder.math.sum function?
The iformbuilder.math.sum function will add the values of your Subform elements to your Parent form from the array and display the sum of those values in Parent level element.
What is the iformbuilder.math.avg function?
The iformbuilder.math.avg function will average the values of your Subform elements to your Parent form from the array and display the sum of those values in Parent level element
How do I aggregate Subform data?
To apply Subform Aggregation to your form, let's start with the Subform element. For the scenario below, we'll be calculating how many employees work in the U.S.
STEP 1. On the Subform inside the form builder, add a Number element. In this example, we'll be using a data column name of how_many_employees_interviewed__live_in_the_us_.
STEP 2. In the Dynamic Value field of the element, put the following:
This will ensure the element is set to 0 with each new record.
STEP 3. Save your form.
Now let's move on to the Parent form.
STEP 4. Add a Subform element to your form, and link the Subform you just created. In this example, it will have a data column name of employee_subform.
STEP 5. Add a Text element to your form. This field will be used to do the aggregation.
STEP 6. In the Dynamic Value of your Text element, put the following syntax:
- iformbuilder.math.sum: This is aggregation function we'll be using.
- subform_aggregation_joe_parent: This is the table name of the Parent form.
- employee_subform: This is the data column name of your Subform element. This should not be confused with the data column name of the element on the subform.
- how_many_employees_interviewed__live_in_the_us_: This is the data column name of the element on the Subform.
STEP 7. Save your form.
STEP 8. Test the functionality on your device.
Download Form Package
Download the Form Package below to use as an example.