Showing results for 
Search instead for 
Did you mean: 
Frequent Visitor

Split Strings in Gallery

Hi All,


My app has one gallery, with ID column and Description column. I have two rowsDescription column has 2 lines. I need to split these two lines and create two entries for same ID.


I used below code. It splits the description into multiple rows but ID gets repeated.


Can someone please let me know what mistake I am making in this code? Thanks in advance.




ForAll(Gallery1.AllItems,Collect(TempCollection, Split(lbl_Desc.Text,"* ")));






Super User
Super User

Something like this should work. 


ForAll(Gallery1.AllItems,Collect(PrimaryCollection,{ID:lbl_ID.TextDesc:First(Split(lbl_Desc.Text,"* "))}));

ForAll(Gallery1.AllItems,Collect(PrimaryCollection,{ID:lbl_ID.TextDesc:Last(Split(lbl_Desc.Text,"* "))}));


Then you can sort PrimaryCollection by ID etc. 

Frequent Visitor

@cwebb365 Thanks for your suggestion. It solves 50%. What I see now is 


ID 1, Text2, and ID 2, Example 2. 


ID 1, Text1 and ID 2, Example 1 entries are missing. 


I noticed that there is a space before the sentence starts and this is causing SPACE to be considered as first record. Also, what if i have three bullet points instead of two? Since this is taking only FIST and LAST, how can i handle the remaining records incase if i have more than two bullet points in future? Thanks for your help.

Super User
Super User

You can substitue FirstN(Split(lbl_Desc.Text,"* "),2) and Last to get the 2nd and 3rd. 

Super User
Super User

For Dynamic, I guess you could do it backwards. 




ForAll(Gallery1.AllItems AS GalItems,Collect(PrimaryCollection,{DescItems: ForAll(AddColumns(Split(GalItems.Desc,"* "),"ID",GalItems.ID),Collect(SecondaryCollection,{ID:ID,Desc:Result}))}));


Basically Nesting ForAll's and using AddColumns to get the alias.ID (id?) from the Gallery1.Allitems into the secondary collection. So it Loops through, then loops through and gets a table of the split's and then loops through those adding new items to the secondary. 


You will need to put if logic's or something to ignore just " "'s or something. Or remove them afterwards with a remove(filter(secondarycollection,desc = " ")) or something like that, but this should get you what you need. Might not be the most performant due to loops but if the item count isn't super high in the scenario should be fine. 

Frequent Visitor

@cwebb365 Thanks for your help. I am getting a syntax error, trying to fix it. It says "The function "Clear" has some invalid arguments"

Super User
Super User

🤷‍♂️ You're going to have to post up what you got or something. I just converted my test functions into your collection names, but it shouldn't be off much. 

Helpful resources

Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (6,256)