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

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

FormuIas - Is it possible to call a user-defined function recursively in Power Apps?
January 31, 2024
Formulas - A beginners guide on how to create and call user-defined functions (UDFs)
January 28, 2024
Formula - How to add a button that converts degrees Centigrade to Fahrenheit and vice versa
May 08, 2023
Formula - How to convert a single delimited string to rows and columns
April 05, 2023
Data - How to group data in a gallery and calculate sums
January 20, 2023
Formula - How to calculate compound interest
November 24, 2022
Utilities - The best way to peform OCR on images of Power Apps Formulas
October 11, 2022
Example - How to use a drop down control to convert currencies
September 27, 2022
Formula - How to parse JSON in Power Apps- 4 examples
September 15, 2022
Data - How to get a row by ordinal number
April 28, 2022
Formula - What to do when the If statement doesn't work?
December 17, 2021
Formula - Boolean And / Or operators - What is the order of precedence?
December 16, 2021
Controls - How to set the data source of a Combo Box to a comma separated string
November 16, 2021
Numbers - 10 examples of how to round numbers
August 18, 2021
Formula - Difference between round, square, and curly brackets
July 20, 2021
Top 3 highlights of upcoming enhancements to the Power Apps language (Power FX)
May 26, 2021
Email - Sending email attachments with the Office 365 Outlook connector
March 30, 2021
Formula - What to try when numbers don't format correctly
March 24, 2021
Controls - How to convert HTML to Text
March 23, 2021
Formulas - how to return all days between two dates
March 15, 2021
Formula - How to use the IF and Switch functions - 3 common examples
February 12, 2021
Location - Finding the closest location and and sorting records by distance, based on the current location of the user
January 24, 2021
Formulas - How to cope with weekends and public holidays in date calculations
January 21, 2021