Repeating sections/Tables

One of the unique features of Cognito Forms is the ability to capture repeating data on forms, such as a variable list of emergency contacts or a list of job references. To capture repeating data, just add a Repeating Section or Table to your form, and add the fields you want to capture in the repeating section.

Syntax

The following extensive example demonstrates how to create an event signup sheet and calculate a variety of things based on who is attending:

Calculations example of an event signup sheet.

This registration form allows families to sign up for a conference hosted at a resort hotel. One registration form allows multiple adult or child attendees to sign up, select optional t-shirt sizes, register for golf to kick off the conference, and prepay for discounted arcade money to use throughout the resort. Here is a detailed breakdown of all of the calculations used to implement this form, highlighting the ease with which calculations can be created for repeating data using Cognito:

Calculated Field Calculation
Number of Adults =Attendees.Count(AdultOrChild = "Adult")
Adult Registration Fee =NumberOfAdults * 150
Number of Children =Attendees.Count(AdultOrChild = "Child")
Child Registration Fee =Math.Max(NumberOfChildren - NumberOfAdults, 0) * 25or=NumberOfChildren > NumberOfAdults ? (NumberOfChildren - NumberOfAdults) * 25 : 0
Number of T-Shirts =Attendees.Count(TShirt != "None")
T-Shirt Fee =Attendees.Count(TShirt.Contains("Youth")) * 15 + Attendees.Count(TShirt.Contains("Adult")) * 20
Number Playing Golf On Friday =Attendees.Count(GolfOnFriday)
Golf Registration Fee =NumberPlayingGolfOnFriday * 65
Total Arcade Bucks =Attendees.Sum(ArcadeBucks)
Arcade Bucks Fee =TotalArcadeBucks * 0.75
Total Registration Fee =AdultRegistrationFee + ChildRegistrationFee + TShirtFee + GolfRegistrationFee + ArcadeBucksFee

Functions

Quick Tip

Select the function name from the list below to see an example of the function in action!

The above example makes heavy use of Count and Sum functions for repeating data, but there are a number of additional functions supported for this type of data:

Function Returns Description
All(Yes/No Calculation) Yes/No Determines whether all items of a repeating section or table satisfy a condition.
Any() Yes/No Determines whether a repeating section or table contains any items.
Any(Yes/No Calculation) Yes/No Determines whether any items in a repeating section or table satisfy a condition.
Average(Numeric Calculation) Number Computes the average of a numeric calculation for each item in a repeating section or table.
Count() Number Returns the number of items in a repeating section or table.
Count(Yes/No Calculation) Number Returns the number of items in a repeating section or table that satisfy a condition.
First() Item Returns the first item in a repeating section or table.
First(Yes/No Calculation) Item Returns the first item in a repeating section or table that satisfies a condition.
Last() Item Returns the last item in a repeating section or table.
Last(Yes/No Calculation) Item Returns the last item in a repeating section or table that satisfies a condition.
Where(Item Number = 1) Item Returns a specific item in a repeating section or table as denoted by the item number.
Max(Numeric Calculation) Number Computes the maximum value of a numeric calculation for all items in a repeating section or table.
Min(Numeric Calculation) Number Computes the minimum value of a numeric calculation for all items in a repeating section or table.
Sum(Numeric Calculation) Number Computes the summation of a numeric calculation for all items in a repeating section or table.
Where(Yes/No Calculation) List Filters the items in a repeating section or table based on a condition.

Referencing repeating data

Because repeating sections can collect a potentially unlimited amount of data, the syntax for targeting field data is slightly different.

Referencing data from all repeating items

To reference repeating data:

  1. Add a Calculation field to your form (outside of your repeating section). If this data is just for internal use, make sure to set the Show This Field option to Internal.
  2. For your expression, denote the title of your repeating section, followed by the .Select function and your field name: =RepeatingSection.Select(Name)
  3. Now, your Calculation field will compile every name inputted into your repeating section.

Referencing repeating data from specific fields.

Referencing data from specific repeating items

The above example targets data from every repeating section item. To reference field data from just one specific repeating item:

  1. Add a Calculation field, or the appropriate field type for the data that you’re collecting. Ex: If you want to reference data from an Email field, add an Email field outside of your repeating section.
  2. For your calculation or default value expression, denote the title of your repeating section, followed by the .Where function to the repeating item you want to reference, and the .Select function to reference the field itself: =RepeatingSection.Where(ItemNumber = 1).Select(Email)
  3. Now, only the email field in the first repeating entry will be targeted.

Referencing and replicating data from the first or last repeating items

First item

You can reference a field in the first repeating item, and default subsequent repeating item fields to the same value:

  1. Select the field that you want to default to in every repeating item.
  2. Set the Default Value to: =if ItemNumber = 1 or Text != null then Text else Form.RepeatingSection.First().Text
  3. Make sure to replace ‘Text’ with the name of your field, and ‘Repeating Section’ with the name of the repeating section on your form.

Select a specific field value from the first item in a repeating section.

Last item

Similarly to the example above, you can reference a field from the last item in a repeating section:

  1. Add a field outside of your repeating section.
  2. Set the Default Value to: =RepeatingSection.Select(Text).Last()
  3. Make sure to replace ‘Text’ with the name of your field, and ‘Repeating Section’ with the name of the repeating section on your form.

Select a specific field value from the last item in a repeating section.

Referencing any items that satisfy a condition

You can use the .Any function to determine whether any items in a repeating section or table satisfy a condition:

  1. Add a Yes/No field outside your repeating section. Set the type to Checkbox.
  2. Set the Show This Field - When option to: =Attendee.Any(Age<12 and Age>0)
  3. Make sure to replace ‘Attendee’ with the name of your field, and update the expression within the parenthesis with your own criteria. In this example, the Yes/No will appear if any of the repeating items contain a value between 0 and 12.

Determine if any of the repeating items contain a value between 0 and 12.