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 (coming soon) 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

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. 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.

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 appropriete 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.