Blog
Formula - How to create comma separated (CSV) list of items
February 25. 2021
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
Related posts
- FormuIas - Is it possible to call a user-defined function recursively in Power Apps?
- Formulas - A beginners guide on how to create and call user-defined functions (UDFs)
- Formula - How to add a button that converts degrees Centigrade to Fahrenheit and vice versa
- Formula - How to convert a single delimited string to rows and columns
- Data - How to group data in a gallery and calculate sums
- Formula - How to calculate compound interest
- Utilities - The best way to peform OCR on images of Power Apps Formulas
- Example - How to use a drop down control to convert currencies
- Formula - How to parse JSON in Power Apps- 4 examples
- Data - How to get a row by ordinal number
- Formula - What to do when the If statement doesn't work?
- Formula - Boolean And / Or operators - What is the order of precedence?
- Controls - How to set the data source of a Combo Box to a comma separated string
- Numbers - 10 examples of how to round numbers
- Formula - Difference between round, square, and curly brackets
- Top 3 highlights of upcoming enhancements to the Power Apps language (Power FX)
- Email - Sending email attachments with the Office 365 Outlook connector
- Formula - What to try when numbers don't format correctly
- Controls - How to convert HTML to Text
- Formulas - how to return all days between two dates
- Formula - How to use the IF and Switch functions - 3 common examples
- Location - Finding the closest location and and sorting records by distance, based on the current location of the user
- Formulas - How to cope with weekends and public holidays in date calculations