cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
DBJ
Helper I
Helper I

How to split column value on delimiter and generate row numbers correctly in collection

I'm able to generate the collection with split column values, but struggling to generate row numbers correctly for the split values

 

ClearCollect(Collection1,ShowColumns(Filter('SPList',ID=1),"column1"));

Set(stored1, Concat(Collection1, column1));

Set(intRow,1);
ClearCollect(Collection2,ShowColumns(ForAll(Split(stored1,";"),{Column1: First(Split(Result,";").Result).Result,RowID:intRow}),"Column1","RowID"));Set(intRow, intRow+1);

 

 

 Getting:

Column1RowID
Value11
Value21
Value31
Value41
Value51

 

Looking for:

Column1 RowID
Value11
Value22
Value33
Value44
Value55
2 ACCEPTED SOLUTIONS

Accepted Solutions
CarlosFigueira
Power Apps
Power Apps

If you want to create a new collection with the column 'column1' from Collection1, and an index of the rows, you can use an expression like this one:

ClearCollect(
    Collection2,
    AddColumns(
        RenameColumns(Sequence(CountRows(Collection1)), "Value", "RowID"),
        "Column1", Last(FirstN(Collection1, RowID)).column1))

The idea is to first create the indices (using the Sequence function) then add the column from the original collection to it by accessing the object by index (using the Last(FirstN(collection, index)) construct).

Hope this helps! 

View solution in original post

RandyHayes
Super User
Super User

@DBJ 

 

I am not following your first few lines of the formula.  You appear to be filtering to 1 specific record and returning just the "column1".  This would mean that your stored1 variable would have the concat of 1 row...so not really needed since it is one row.

 

If you are just working with one row and a column that has delimited items in it, then consider this following formula:

Clear(colResults);
ForAll(
    Split(LookUp(SPList, ID=1, column1), ";"),    
    Collect(colResults, {Column1: Result, RowID: CountRows(colResults)+1})
)

 

If you are doing this over several rows from your data source, then consider this formula:

Clear(colResults);
ForAll(
    Split(
        Concat(
             Filter(SPList, 'lookupCriteria'), 
             column1 & ";"
        ), 
        ";"
    ),    
    Collect(colResults, {Column1: Result, RowID: CountRows(colResults)+1})
)

 

I hope this is helpful for you.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

4 REPLIES 4
CarlosFigueira
Power Apps
Power Apps

If you want to create a new collection with the column 'column1' from Collection1, and an index of the rows, you can use an expression like this one:

ClearCollect(
    Collection2,
    AddColumns(
        RenameColumns(Sequence(CountRows(Collection1)), "Value", "RowID"),
        "Column1", Last(FirstN(Collection1, RowID)).column1))

The idea is to first create the indices (using the Sequence function) then add the column from the original collection to it by accessing the object by index (using the Last(FirstN(collection, index)) construct).

Hope this helps! 

RandyHayes
Super User
Super User

@DBJ 

 

I am not following your first few lines of the formula.  You appear to be filtering to 1 specific record and returning just the "column1".  This would mean that your stored1 variable would have the concat of 1 row...so not really needed since it is one row.

 

If you are just working with one row and a column that has delimited items in it, then consider this following formula:

Clear(colResults);
ForAll(
    Split(LookUp(SPList, ID=1, column1), ";"),    
    Collect(colResults, {Column1: Result, RowID: CountRows(colResults)+1})
)

 

If you are doing this over several rows from your data source, then consider this formula:

Clear(colResults);
ForAll(
    Split(
        Concat(
             Filter(SPList, 'lookupCriteria'), 
             column1 & ";"
        ), 
        ";"
    ),    
    Collect(colResults, {Column1: Result, RowID: CountRows(colResults)+1})
)

 

I hope this is helpful for you.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

@CarlosFigueira ,

 

I'm trying to split the values from column1, with your example the collection still displays a delimited value. @RandyHayes  answered my question with his first example. Thanks for taking the time to look at it though and showing me the sequence function, I'll probably use it at some point.

@DBJ 

Actually the approach that @CarlosFigueira could work as well, it is just another trick to get sequential numbers into a table.

 

Glad it is working for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

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

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

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 (1,560)