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.
Clear(PrimaryCollection);Clear(TempCollection);Clear(SecondaryCollection);
ForAll(Gallery1.AllItems,Collect(PrimaryCollection,{ID:lbl_ID.Text,Desc:lbl_Desc.Text}));
ForAll(Gallery1.AllItems,Collect(TempCollection, Split(lbl_Desc.Text,"* ")));
ForAll(TempCollection,
Collect(SecondaryCollection,{ID:lbl_ID.Text,Desc:Result}))
Something like this should work.
Clear(PrimaryCollection);
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.
@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.
You can substitue FirstN(Split(lbl_Desc.Text,"* "),2) and Last to get the 2nd and 3rd.
For Dynamic, I guess you could do it backwards.
Do
Clear(PrimaryCollection);Clear(SecondaryCollection);
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.
@cwebb365 Thanks for your help. I am getting a syntax error, trying to fix it. It says "The function "Clear" has some invalid arguments"
🤷♂️ 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.
User | Count |
---|---|
263 | |
110 | |
98 | |
55 | |
40 |