Description
The COUNT
function counts the number of non-blank values in a subform's field, in one or more fields, or in a multiple-select field.
Usage
COUNT(VALUE1, VALUE2, VALUE3, ...)
COUNT(SUBFORM_FIELD.FIELD_NAME)
Remarks
When used with subform fields, the argument to COUNT()
must include a reference to the form's subform field and then the field within the subform, using the dot notation.
The COUNT
function accepts arguments of any type.
Examples
Counting subrecords
If you have a household survey form with a "Members" subform, you can use the COUNT
function to count the number of members in the household:
COUNT(MEMBERS.NAME)
This will count the number of members for each household record with a non-blank NAME
.
If you want to count all subrecords of the record, you can also write:
COUNT(MEMBERS._id)
Here, we refer to the record's built-in, auto-generated ID using the _id
symbol. Since every record always has an ID, this effectively counts all records.
Counting number of phone numbers provided in a record
If you have three optional fields in a form for different types of phone numbers, you might want to know how many non-blank phone numbers have been provided.
For example, you could write:
COUNT(FIXED_LINE_PHONE_NUMBER, MOBILE_PHONE_NUMBER, OTHER_NUMBER)
If the respondent has provided a value for all three fields, the result will be three. If they have only provided a fixed line and mobile number, the result will be 2.