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
Sample Shareholdings Data |
Fiona Forrest holds 100 Common shares Fiona Forrest holds 5 Preferred shares Gemma Germinate holds 50 Common shares Herbert Horticulture holds 100 Common shares Isabella Iridescence holds 25 Common shares Isabella Iridescence holds 5 Preferred shares Julian Juniper holds 10 Common shares |
Simple Count
A simple count
function will output a numerical value. Since it's not logic or opening a collection loop, there's no need for the opening {#} tag.
{collectionVariable | count}
Input | {shareholdings | count} |
Meaning | Count all shareholdings |
Output | 7 |
Count with uniqBy
To count the only distinct and unique records in the collection, filter out duplicates with uniqBy
. For more information, check out this article on Removing Duplicates with uniqBy.
{collectionVariable | uniqBy:'distinctVariable' | count}
Input | {shareholdings | uniqBy:'shareholder_participant_profileID' | count} |
Meaning | Count all shareholdings by unique shareholder participant ID number |
Output | 5 |
Count with filters
To refine the data before counting it, use the count
function with the appropriate pre-defined or ad hoc filters. For more information, check out this article on Using Pre-defined and Ad Hoc Filters to Refine Data.
{collectionVariable | filter:'filterVariable':'filterValue' | count}
Input | {shareholdings | filter:'className':'Preferred' | count} |
Meaning | Count all shareholdings for share class name "Preferred" |
Output | 2 |
Count with logic
A count function used with logic will compare the count result with your logic parameters. For more information, check out this article on Logic & Conditions.
{#collectionVariable | count | countLogic:1}Conditional Content for countLogic1{/}{#collectionVariable | count | countLogic:2}Conditional Content for countLogic2{/}
Sample Shareholdings Data | ||
Fiona Forrest - 100 Common Gemma Germinate - 50 Common Herbert Horticulture - 100 Common Isabella Iridescence - 25 Common Julian Juniper - 10 Common |
Kiefer Kernel - 1 Common | |
Input | {#shareholdings | count | gt:1}All of the shareholders consent{/}{#shareholdings | count | lt:2}The sole shareholder consents{/} | |
Meaning |
IF the counted number of shareholdings is greater than 1, then populate with plural shareholder phrasing. IF the counted number of shareholdings is less than 2, then populate with singular shareholder phrasing. |
|
Output | All of the shareholders consent | The sole shareholder consents |