Articles on: Expression language

List (array) functions

Count

It is possible to count number of items in list.
{% count({line_items}) > 3 ? 'More than three' : 'Less than three' %}


Max

Returns maximum value of list of elements or separate field values.
{% max({line_items::quantity}) %}

or
{% max({dataField1}, {dataField2}, ..., {dataFieldN}) %}


Min

Returns minimum value of list of elements or separate field values.
{% min({line_items::quantity}) %}

or
{% min({dataField1}, {dataField2}, ..., {dataFieldN}) %}


Sum

It is possible to calculate sum of table column using following code.
{% sum({line_items::amount}) %}


Sumproduct

The sumproduct function multiplies the corresponding items in the arrays and returns the sum of the results.
{% sumproduct({line_items::amount},{line_items::price}, {line_items::anotherColumn}) %}


Average

It is possible to calculate average of table column using following code.
{% avg({line_items::amount}) %}

The Number component should be used when creating calculations or using sum, average, sumproduct functions.

Join

The join(delimiter, array) function concatenates field values with specified separator. Last argument is always used as the separator.
{% join(";", {field1}, {field2}, {field3}, ..., {fieldN}) %}
{% join(";", [{field1}, {field2}, {field3}, ..., {fieldN}]) %}


Iterate list of elements (array map)

Iterates over list of elements and executes expression for each element. Returns new list.
{% iterate({line_items}, 'quantity*price') %}


{% map({line_items}, 'quantity*price') %}


Filter list of elements

Filters a list of elements by executing the given expression for each element. Returns new list.
{% filter({line_items}, 'price > 10.1') %}


Iterate, map, and filter functions also accept a third parameter, which can be used as a 'reference' in the expression:

{% iterate({list}, 'value === reference', 3) %} // reference = 3
{% map({list}, 'value === reference', 3) %} // reference = 3
{% filter({list}, 'value === reference', 3) %} // reference = 3


Collect unique values from list

Collects unique values from and counts them. Returns new list with following structure:
[{"value": "Value", "count": 3, "raw_value": "Value"}, {"value": "Value 2", "count": 1, "raw_value": "Value 2"}]
{% collect_unique_values({array}, {array_of_values_to_exclude}, {expression_to_execute_for_each_item}) %}


Example use case:
This is the JSON example dataset to demonstrate the functionality of collect_unique_values function.
[{"array_of_names":[{"name":"marian"},{"name":"bruno"},{"name":"erik"},{"name":"tanel"},{"name":"michal"},{"name":"erik"},{"name":"erik"}]}]


Lets say we want to make a list of unique values from the "array_of_names" data field, but exclude the names "tanel" and "michal".
The expression to do that would look like this:
{% join(", ", iterate((collect_unique_values({array_of_names}, ["michal","tanel"], "name")), "value")) %}


Flatten list

Flattens list.
{% flatten(iterate({orders}, "{line_items}")) %}


Sort list

The function sort([array], [expression], [direction])) allows you to sort list of elements by the key value. The direction can be either ASC or DESC. The function returns new array with sorted items.

{% sort({line_items}, "quantity", "DESC") %}
{% sort({line_items}, "quantity*price", "ASC") %} 
{% sort({line_items}, "quantity > 10 ? 1 : 0", "ASC") %}

Updated on: 04/02/2025

Was this article helpful?

Share your feedback

Cancel

Thank you!