Counting Data

Doc Auto Team
Doc Auto Team
  • Updated

The count function allows you to count the number of instances for a specific record. This function may be used with filters to count specific data. This function may also be combined with logic and conditionals to specify output results. Finally, this function can be used for math operations.

Syntax and Use Cases

A simple count function will output a numerical value. Please see examples in the Simple Count section below.

{collectionVariable | count}

A filtered count function will output a numerical value based on the criteria specified. Please see examples in the Filtered Count section below. For more information on filtering data, please see this article on Using Pre-defined and Ad Hoc Filters to Refine Data.

{collectionVariable | filter:'expectedResult' | count}

A count function used with logic will select the appropriate output based on the criteria specified. Please see examples in the Count with Logic section below. For a more detailed article on count logic, please see this article on Conditions: IF statements.

{#collectionVariable | count | countLogic:1}countLogic1Result{/}
{#collectionVariable | count | countLogic:2}countLogic2Result{/}

The count function by itself will only output a numerical value. Only when combined with a logic statement will it be able to output specific text. When it is used independently of logic statements, there is no need to open the collection with #.

 

Example: Share Calculations

Sample Dataset

Issued and Outstanding Shares:

  • 100 Common @ $1.00/share - voting

  • 100 Preferred @ $0.10/share - non-voting

Common Shareholders:

George Bluth (confirmed) - 30 Common shares
Lucille Bluth (confirmed) - 30 Common shares
Michael Bluth (confirmed) - 20 Common shares
Lucille Austero (inactive) - 20 Common shares
George Oscar Bluth (incoming) - 10 Common shares
Lindsay Bluth (incoming) - 5 Common shares
Buster Bluth (incoming) - 5 Common shares

Preferred Shareholders:

Lucille Austero (inactive) - 100 Preferred shares
George Michael Bluth (confirmed) - 45 Preferred shares
Maeby Fünke (confirmed) - 45 Preferred shares
Tobias Fünke (outgoing) - 10 Preferred shares
Annyong Bluth (incoming) - 5 Preferred shares
Steve Holt (incoming) - 5 Preferred shares

 

Simple Count

 

Count

Input

{shareholders | count}

Meaning

Count all the shareholders

Output

13

 

Count with uniqBy

Input

{shareholders | uniqBy:'name' | count}

Meaning

Count all unique shareholders on the basis of name only

Output

12

Filtered Count

 

Count with filter

Input

{shareholdings | status:'confirmed' | count}

Meaning

Count confirmed shareholders only

Output

5

 

Count with multiple filters (pre-defined and ad hoc)

Input

{shareholdings | status:'confirmed' | filter:'voting':'true' | count}

Meaning

Count confirmed voting shareholders

Output

3

Count with Logic

 

Count with Logic

Input

{#shareholdings | status:'confirmed' | filter:'voting':'true' | count | lt:2}The sole voting shareholder agrees{/}{#shareholdings | status:'confirmed' | filter:'voting':'true' | count | gt:1}All of the voting shareholders agree{/}.

Meaning

IF the counted number of confirmed voting shareholders is fewer than 2, then populate with ‘The sole shareholder agrees’
IF the counted number of confirmed voting shareholders is greater than 1, then populate with ‘All of the voting shareholders agree’

Output

Because the counted number of shareholders is 3, therefore populate with:

All of the voting shareholders agree.