This article requires the **GP Nested Forms** perk.

Buy Gravity Perks to get this perk **plus 46** other premium Gravity Forms plugins!

## Overview

One of the most powerful features of GF Nested Forms is its ability to perform calculations on the Parent Form with data in the Child Form. In this tutorial we’re going to do a deep dive into the different calculations and cover some common use cases for those calculations. Let’s begin.

## :count

The ** :count** merge tag modifier returns the total number of child entries attached to the Nested Form field. If there are two child entries submitted for a Nested Form field, this merge tag will return 2.

`{Players:1`

**:count**}

### Numbering Entries

A common use for the ** :count** modifier is to attach numbering to the Nested Forms entries themselves. For example, an order form with line items.

You can achieve this numbering sequence by utilizing a couple of Nested Forms specific merge tags and Number fields. Here’s how you would set it up:

In your Parent form, add a Number field, enable calculation, and use the ** :count** merge tag modifier in the calculation to count the number of Nested Form entries. Set this field as hidden.

In the Nested Form, add a Number field and in its Default Value enter the `{Parent}`

merge tag to pull the value from our newly-added Number field into the Child Form.

That’s it. When *Add Entry* is clicked, the modal will appear and the `{Parent}`

merge tag will pull in the current entry count into the Child Form. For the first entry, that will be 0. Once a new entry is added to the form, the count on the Parent form goes up by 1. The next child entry will then be numbered 1 and so on.

`+1`

to the Parent form calculation.### Calculated Quantities

Another use for the ** :count** merge tag modifier is to calculate quantities based on the number of Nested Form entries.

For example, say you have a Player sign up form and you want to charge a certain amount for each player on the team *and* you want to offer quantity-based discounts with GF Conditional Pricing. This is made possible by adding GF Copy Cat to the mix. Here’s how you would set that up:

Add a Number field to the Parent form, enable calculation, and enter only the Nested Form merge tag with the ** :count** modifier as the calculation. Set this field as hidden.

Add a Product field to the form. Note the Field ID for this field.

Within the *Appearance* tab of the Number field, enter the Copy Cat Custom CSS class to copy the calculated Number field’s value to the Quantity of the Product field. The syntax for this is the following:

`copy-x-to-y.3`

where `x`

is the Field ID for the Number field and `y`

is the Field ID for the Product field. The `.3`

tells Copy Cat to copy into the Quantity portion of the Product field.

You’re well set. When a customer adds an entry to the Nested Form, the merge tag will populate your hidden Number field and Copy Cat will copy that number to the Product field’s quantity. You can then use Conditional Pricing to offer bulk pricing.

## :total

The ** :total** merge tag modifier returns the sum of all child entry order totals. For example, if Child Entry #1 has a total of

`$10`

and Child Entry #2 has a total of `$25`

, this merge tag would return `35`

.`{Players:1`

**:total**}

### Collecting a Single Payment for Multiple Orders

With the

merge tag modifier, you can add any number of Products to a Child form and only have to collect payment once in the Parent form. This simplifies the purchasing process and gives your customers a better user experience. Setting this up is simple:**:total**

- Add a Product field to your Child form and set appropriate Price and Quantity settings.
- Add a Product field to your Parent form, set its
*Type*to Calculation and disable Quantity. For the Calculation, insert the merge tag for the Nested Form with themerge tag modifier.`:total`

That’s all there is to it. The Product totals for all Child Entries will be passed to the Product field in the Parent form, and you can collect payment one time in the Parent form using any of the Gravity Forms Payment Add-Ons.

## :sum

The ** :sum** merge tag modifier returns the sum of the specified target field’s value from each child entry. For example, if you have a Number field inside your Nested Form and Child Entry #1 has a value of

`4`

and Child Entry #2 has a value of `3`

, this merge tag will return `7`

.The syntax for this calculation is a little more complicated than the others. It requires you to specify exactly which field in the Child Form you want to sum, preceded by an `=`

. For example, let’s say you have a Nested Form Field in your Parent Form with an ID of `1`

. Inside your Child Form, there is a Number field with an ID of `2`

. The merge tag you would use in the Calculation in the Parent Form is this:

`{Players:`

`1`

`:sum`

`=2`

`}`

### Sum the Number of Reserved Seats

With the ** :sum** merge tag modifier you can add up the sum of any field, and a practical example of that is if you’re trying to determine how many seats are required for an event.

Let’s say you have a form that will be used for different companies to register attendees for an industry awards banquet. Each company can reserve a certain number of attendees and those attendees can optionally bring a guest.

Nested Forms can handle registering multiple attendees in a single form, and we can use the ** :sum** merge tag to figure out exactly how many seats are needed. Let’s get started.

Add a Drop Down Field in your Child form to indicate whether the attendee will bring a guest. Check *show values* and set the values to 2 for “Yes” and 1 for “No”. Note the Field ID, we’ll be using it later.

In your Parent Form, add a Number field, Enable Calculation, and insert the Sum merge tag. Enter the Field ID noted above after the equals.

That’s all there is to it. The ** :sum** merge tag modifier will automatically sum up the value from the Drop Down field into the Number field on the Parent Form.

Gravity Forms Advanced Calculations adds support for complex mathematical functions directly within your Number and Product fields. It reinvents Gravity Forms calculations from the ground up with an array of advanced mathematical functions, clever conditionals, formula optimizations, and a potent formula editor that puts all of these features at your fingertips.

## Wrapping Up

As you can see, calculations in Nested Forms offer tons of flexibility for passing values from the Child Form to the Parent Forms. We’ve talked about some common use cases we’ve seen from our customers, but if there’s anything we haven’t covered, please let us know in the comments. We love hearing all of the interesting ways our customers use our Perks!

Did this resource help you do something awesome with Gravity Forms?

Then you'll absolutely love Gravity Perks; a suite of **46+ essential add-ons for Gravity Forms** with support you can count on.

Gine B Lopa says

Thank you for this tutorial, I want to use it on my website. Gine B Lopa Name Combiner

Samuel Bassah says

Hi Gine,

You’re welcome. Glad to know the tutorial is useful to you.

Best,

Addy says

How can I get the total number of guests from the seats that RSVP’d for an event? I would like to calculate the total number of guests that are attending and also get the total of guests that declined an RSVP from a radio or drop box selection.

Samuel Bassah says

Hi Addy,

You could add two Hidden fields to the Child form and set the default value of these Hidden fields to 1. You will then set up conditional logic on these Hidden fields to show depending on the selection. One would show if the guest is attending and one will show if the guest declined. With these hidden fields, you can use the sum modifeir to get the total of their values in two separate Number fields on the Parent form. I hope this helps.

Best,

Johan says

My nested form will allow for 12 child entries to be created. They are 12 units in an insurance form. Each child entry has a number field that has a total value inside.

Now in the parent form, I would like to have 12 number fields that are synced with those total fields in the child entry (I imagine something like ‘nestedfield:1:entry=1’ would give me the value of the first entry from the nested form aka unit1).

The reason I need this is because in the parent field, I want to calculate how much percentage each unit has in the total insurance claim (=all child entries together). I already have this total with the :sum modifier. I just need the separate numbers from each unit so I can calculate the percentage. None of the modifiers above seem to do this so i’m not sure if it is possible?

Example: Unit1: $1000, Unit2: $1000, Total: $2000, each unit has 50% in the claim. I imagine something like ‘nestedfield:1:entry=1’ would give me the value of the first entry which in this case would be 1000.

Thank you in advance.

Ryan Donovan says

Hello Johan, if you have a Gravity Forms license could you please send us a request via our support channel found here so we can take a look into this for you? Thank you!