In a formula-type column, the NB_ELEMENTS() function counts the number of items contained in the selected columns, including columns containing multiple values, such as fields of the Linked Table Column type.
-
Function name:
NB_ELEMENTS()
Syntax
NB_ELEMENTS(column_1, column_2, ...)
Calling function parameters in TimeTonic:
- $field_name = field (link, linked table column, number, selection, formula, text...).
- "free text" = free text to add inside quotes.
- do not use quotes for numbers.
Parameters
| Parameter | Description |
|---|---|
column_1, column_2, ... |
The columns whose elements are counted. Can include a Linked Table Column containing multiple values. |
Example 1
NB_ELEMENTS($Documents reçu)
I counted the number of items in the Documents reçu column to find out the total number.
Example 2
NB_ELEMENTS($Documents reçu, $Souscription)
I counted the number of items in the Documents reçu column plus the number of items in the Souscriptions column, to know the total number of documents contained in my client's file.
Example 3
Similarly, I can count the number of items linked to another table.
NB_ELEMENTS($Facture)
I counted the number of invoices in my Facture column issued to a given client.
Return type
The function returns a number (the count of items).
The output type format of the result can be configured in the output field options of the formula editor. For more details, see Output format options in the Formula Column article.
Business use case
NB_ELEMENTS() counts attached items: number of documents in a client file, number of linked invoices, number of products in an order.
Best practice
To add values (rather than count them), use SUM_ELEMENTS(); for the smallest or largest value, use MIN_NUM_ELEMENTS() or MAX_NUM_ELEMENTS().