cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
desreed
Level: Powered On

Splitting just one column into multiple rows

Hi all.  First time poster, so apologies in advance if I'm not following some etiquette!

 

I've got an issue with using the Split function.  I have managed to get a collection that looks something like this:

 

Collection1

IDTags
1Tag1;Tag2
2Tag2;Tag3
3Tag1
4Tag4
5Tag2;Tag4

 

What I'm hoping is to turn that into a collection that looks like this:

 

Collection2

IDTags
1Tag1
1Tag2
2Tag2
2Tag3
3Tag1
4Tag4
5Tag2
5Tag4

 

I can do this is seconds using PowerBI when I need to.

 

Basically I'm trying to use a few text fields to store the results of multi-value combo box to 'tag' records with certain info.  I can do the patching of the data into the one text cell, but I'm struggling to split it back out to make it a usable dataset in the app.

 

Any help on this would be really gratefully received.  Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Splitting just one column into multiple rows

Here is an example where I first create your Collection1 as sample data then I create Collection2 by looping through Collection1. As the formula it loops through Collection1 it also splits the tags and loops through them and then adds a row to Collection2.

You should be able to copy and paste this example into a button and run it to see if it is giving you the results you need. 

 

ClearCollect(Collection1, {ID:1, Tags:"Tag1;Tag2"}, {ID:2, Tags:"Tag2;Tag3"}, {ID:3, Tags:"Tag1"}, {ID:4, Tags:"Tag4"}, {ID:5, Tags:"Tag2;Tag4"});
Clear(Collection2);
ForAll(Collection1, ForAll(Split(Tags,";"),Collect(Collection2,{ID:ID, Tags:Result})));


--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

View solution in original post

2 REPLIES 2
Super User
Super User

Re: Splitting just one column into multiple rows

Here is an example where I first create your Collection1 as sample data then I create Collection2 by looping through Collection1. As the formula it loops through Collection1 it also splits the tags and loops through them and then adds a row to Collection2.

You should be able to copy and paste this example into a button and run it to see if it is giving you the results you need. 

 

ClearCollect(Collection1, {ID:1, Tags:"Tag1;Tag2"}, {ID:2, Tags:"Tag2;Tag3"}, {ID:3, Tags:"Tag1"}, {ID:4, Tags:"Tag4"}, {ID:5, Tags:"Tag2;Tag4"});
Clear(Collection2);
ForAll(Collection1, ForAll(Split(Tags,";"),Collect(Collection2,{ID:ID, Tags:Result})));


--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

View solution in original post

desreed
Level: Powered On

Re: Splitting just one column into multiple rows

@Jeff_Thorpe  - Thank you!  I did as you suggested and pasted it in and got it working.  I've also figured out how to adjust the final bit of your code to attach it to existing collections and connections and Ive got what I was looking for.  Really great.

 

I can't pretend I understand that last bit of code though:

 

ForAll(Collection1, ForAll(Split(Tags,";"),Collect(Collection2,{ID:ID, Tags:Result})))

 

But, I've got it working, and it does exactly what I need now.  So thank you very much, particularly for the quick answer!

 

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (4,580)