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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Need to create a colle...
Power Apps
Answered

Need to create a collection from 2 comma-separated columns in a sharepoint list

(1) ShareShare
ReportReport
Posted on by 185
Hi,
 
I have a SharePoint list that is something like this:
 
I need to create a collection which will have 2 columns (IDno and Order).
 
I need the collection to be:
IDno         Order
===========
3               1
1               2
 
based on the above SharePoint list.
 
The SharePoint list will end up having more fieldIDs and FieldOrder values in it.  Just for the example it has two values.
 
I've been trying using:
 
ForAll(Split(fieldIDs, ",") As selectedIDs,
    Collect(colIDandOrder, { IDno: Value(selectedIDs.Value) } )
)
 
This does get a collection with the fieldIDs in it.
 
Can I then populate the collection with the FieldOrder values.
 
I feel that I should be able to do it by updating the collection from the first row to the last with the split of FieldOrder, but I can't figure it out.
 
Any help is much appreciated.
 
Pete
 
Categories:
I have the same question (0)
  • Verified answer
    MParikh Profile Picture
    521 Super User 2026 Season 1 on at
    Hi @petewalburn,
     

    The key is to split both columns simultaneously using a numeric index to pair values by position.

    Instead of iterating over one split column, use Sequence to generate row numbers, then use Index to pull the matching value from each split at that position.

    ClearCollect(
        collDandO,
        ForAll(
            Sequence(CountRows(Split(fieldIDs, ","))),
            {
                IDno: Value(Index(Split(fieldIDs, ","), Value).Value),
                Order: Value(Index(Split(fieldOrder, ","), Value).Value)
            }
        )
    )
     

    Sequence(CountRows(Split(fieldIDs, ","))) generates a numbered sequence, one per item in the comma-separated string. Value inside the ForAll refers to the current position number. Index(..., Value).Value then picks the nth item from each split result, keeping both columns in sync.

    One thing worth checking: both comma-separated strings need the same number of items. If fieldIDs has 3 values and fieldOrder has 2, the Index call on the shorter string will return blank or error on the last row.

    The original approach of ForAll(Split(fieldIDs, ",")) only iterates over one column. There is no way to reference the nth item of a second split inside that loop without using Index on the full split result, which is what this formula does.

    This pattern scales as the SharePoint list grows with no changes needed to the formula.

     

    Thank you! 
    Proud to be a Super User!
    📩 Need more help?
    ✔️ Don’t forget to Accept as Solution if this guidance worked for you.
    💛 Your Like motivates me to keep helping
  • Verified answer
    11manish Profile Picture
    3,333 on at
    Can you try below : 
     
    With(
        {
            ids: Split(ThisItem.fieldIDs,","),
            orders: Split(ThisItem.FieldOrder,",")
        },
        ClearCollect(
            colIDandOrder,
            ForAll(
                Sequence(CountRows(ids)),
                {
                    IDno: Value(Last(FirstN(ids, Value)).Value),
                    Order: Value(Last(FirstN(orders, Value)).Value)
                }
            )
        )
    )
  • Verified answer
    DP_Prabh Profile Picture
    381 on at

    Hi @petewalburn,

    The approach you are using only split the fieldIDs and stored them in the collection, so the FieldOrder values were not correctly linked to the corresponding IDs. Since both fieldIDs and FieldOrder are stored as comma-separated strings, we need to split both values and match them by their position (index).

    To solve this, we used Split() to convert both strings into tables and Sequence() to iterate through their indexes. During each iteration, the corresponding ID and Order value are retrieved and added together to the collection. This ensures that each ID is correctly mapped with its matching order.

    Updaated Code

    Clear(colIDandOrder);
    
    With(
        {
            allIDs: Split(fieldIDs, ","),
            orders: Split(FieldOrder, ",")
        },
        ForAll(
            Sequence(CountRows(allIDs)) As i,
            Collect(
                colIDandOrder,
                {
                    IDno: Value(Index(allIDs, i.Value).Value),
                    Order: Value(Index(orders, i.Value).Value)
                }
            )
        )
    )
    

    Resulting Collection

    IDno Order
    3 1
    1
    1
     
     
    I hope this works for you!
     
  • petewalburn Profile Picture
    185 on at
    Thank you all.  Each of these answers work perfectly.
     
    I realised that I needed and index so I could find the corresponding Order for each ID, but didn't even think about using Sequence.
    It's kind of obvious now!
     
    Thank you all.
     
    Pete

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 424

#2
WarrenBelz Profile Picture

WarrenBelz 355 Most Valuable Professional

#3
11manish Profile Picture

11manish 290

Last 30 days Overall leaderboard