Blog

Formula - How to create comma separated (CSV) list of items

A common requirement is to build a comma separated list based on items from a data source or collection. This post demonstrates this technique by building a CSV string of selected items from a combo box.

There are many situations where it's necessary to build a comma separated (CSV) list of items from a data source or collection. Some examples include:

  • Showing a CSV list of items in a label.
  • Building a single string of values to pass to a Flow.
  • Building a comma separated list of items to store in a text field in a data source.

Formula to create a CSV string

As a demonstration, we'll add a combo box to a screen, and display a CSV list of selected items in a label.


The syntax to carry out this task is shown beneath:

With({concatResult:Concat(cboDocuments.SelectedItems,  ThisRecord.Title  & ", ")},
Left(concatResult, Len(concatResult)-2)
)

The screenshot beneath shows a combobox with three items selected: ' Tenancy Agreement', ' Energy Certificate', 'Inventory Checklist'. The label beneath the combobox shows the CSV list of selected items.

Explanation

How does this formula work? Within the call to the 'With' statement, we concatenate the selected items in the combo box with this expression:

Concat(cboDocuments.SelectedItems,  ThisRecord.Title  & ", ")

The Concat function takes two arguments: the data source, and the output to produce for each row in the data source. In this example, we build an expression that outputs the title field followed by a comma and space.

The consequence of this expression is that it produces a trailing comma and space at the end of the concatenated string. Therefore, we strip the 2 trailing characters by calling the left function to return the concatenated string, minus 2 characters.

Conclusion

In this post, we walked through how to build a CSV string by calling the Concat function, and stripping the trailing characters that may appear at the end of the concatenated string.

Related posts