web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Correct combination of...
Power Apps
Answered

Correct combination of Concat with Collect to pass collection values to data table in 1 line

(0) ShareShare
ReportReport
Posted on by 102
  • I have a listbox in a gallery that allows multi selections.
  • OnSelect property of listbox collects values and passes them to data table. Both formulas: Collect(ServicesSelected,ListBox.Selected.Value) and  Collect(ServicesSelected,ListBox.SelectedItems.Value) works to pass values but they appear on multiple lines. I would like to concat the values to appear on just one line.

acoliva_0-1694265936006.png

  • I added a text box as a test of the concat formula and it works well with Concat(ListBox.SelectedItems.Value,Concatenate(Text(Value)," ;"))

acoliva_2-1694266093208.png

  • When I try to combine the concat and collect in the OnSelect property of the listbox, I cannot achieve the single string. I have tried with this formula: Concat(Collect(ServicesSelected,ListBox.SelectedItems.Value),Concatenate(Value(ListBox.Selected.Value)," ;"))

There is no initial error but when selecting value it either continues to add multiple rows or duplicates and when app is played I get this error

acoliva_3-1694266257626.png

 

Am I just missing something in the syntax of the concat formula or am I not approaching this correctly? TIA

 

 

 

 

Categories:
I have the same question (0)
  • AhmedSalih Profile Picture
    6,678 Moderator on at

    Hello, @acoliva , try this out:

    Concat(ListBox.SelectedItems.Value,Concatenate(Text(Value),";"),";")
    

     


    If my reply helped you, please give a 👍 If it solved your issue, please give a 👍 & accept it as the Solution to help other community members find it more.

    Visit my Blog: ahmedsalih.blog

    Visit my YouTube Channel: https://www.youtube.com/@powerplatformplace/videos

     

  • acoliva Profile Picture
    102 on at

    Thanks for answering but the concat by itself works perfectly fine. I need to combine it with the Collect function to pass the values in a single line.

  • Verified answer
    LaurensM Profile Picture
    12,516 Moderator on at

    Hi @acoliva,

     

    I don't think you need to combine Concat & Concatenate functions, additionally the Collect function may not function as expected. Below I will display how to avoid the nested Concat & Concatenate functions and use a direct reference to the gallery to avoid using a collection.

     

    (1) Concat accepts 3 parameters:

    Concat(
     //Your input table
     ListBox.SelectedItems,
     //Define the column to concatenate
     Value,
     //Define the separator
     " ;"
    )
    //This will result in Item1 ;Item2 ;Item3
    //In my next code block I will add some code to append Item3 with a semicolon as well (as present in your example)

     

    Using a Collect() function within the OnSelect will cause duplicates in your list. Imagine Item 1 in your gallery, you Select 2 in the ListBox (which will save 1 ; 2 ; to your gallery, since 1 is auto-selected), when you press 3 it will save another row containing 1 ; 2 ; 3 ; for the same gallery item. In other words, you will create multiple rows within your collection for the same gallery item when you select an additional item in the ListBox / unselect an item.

     

    If possible, I would recommend not using a collection and using a direct reference to your Gallery instead:

     

    (2) Use the Concat as the parameter of a Gallery.AllItems ForAll reference:

    //This function can be used as e.g. in the Items property of another gallery
    ForAll(
     //Rename to the correct gallery name containing the listboxes
     GalleryName.AllItems,
     //Since your last item in the example also had " ;" at the end I added & " ;"
     //Remove this should you not want it to be displayed after the last item
     Concat(
     ThisRecord.ListBox.SelectedItems,
     Value,
     " ;"
     ) & " ;"
    )

    The code above can also be used as an input to save all rows to a collection at once instead of using the Collect code in the OnSelect / OnChange of each ListBox:

    ClearCollect(
     ServicesSelected, 
     ForAll(<See Code Above>)
    )

     

    If this solves your question, would you be so kind as to accept it as a solution & give it a thumbs up.

    Thanks!

  • acoliva Profile Picture
    102 on at

    Thank you so much for not only solving my question but also the clear explanation to understand this better in the future. Worked perfectly!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 765 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 272

Last 30 days Overall leaderboard