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

Merge one collection with another

Hi all- I'm at my wit's end here.  I have looked through dozens of similar posts to follow examples of how to get two collections (or even 2 sharepoint lists) combined into a single collection.  The two collections I am working with are called:

 

DirectoryData  and

ProfileData

 

I am trying to combine into a single collection called DeepSearchData whereby the collections are matched by an email address stored in each collection as a column:

 

FCDUserEmail is the column in DirectoryData and

FCDProfileEmail is the column in ProfileData that I am matching the data sets by.

 

Can anyone help me with the syntax for this operation?

1 ACCEPTED SOLUTION

Accepted Solutions
jhall
Level 8

Re: Merge one collection with another

Assuming I start with two Collections (DirectoryData and ProfileData), I can merge them into a single table and match up entries similar to the following:

 

ClearCollect(DirectoryData,Table({FirstName:"John",FCDUserEmail:"test@test.tst"},{FirstName:"Bob",FCDUserEmail:"test2@test.tst"}));
ClearCollect(ProfileData,{LastName:"Smith",FCDProfileEmail:"test@test.tst"});
ClearCollect(mergedData,AddColumns(DirectoryData,"LastName",LookUp(ProfileData,FCDUserEmail=FCDProfileEmail,LastName)))

 

The third line creates a new Collection called mergedData, populates it w/ the contents of DirectoryData + a new column that is a LookUp from ProfileData where the values between your two email columns FCDUserEmail and FCDProfileEmail match.

View solution in original post

8 REPLIES 8
Super User
Super User

Re: Merge one collection with another

Hi @jsantan73 

Is the relationship between the datasources a one-to-one or a one-to-many?

jhall
Level 8

Re: Merge one collection with another

Assuming I start with two Collections (DirectoryData and ProfileData), I can merge them into a single table and match up entries similar to the following:

 

ClearCollect(DirectoryData,Table({FirstName:"John",FCDUserEmail:"test@test.tst"},{FirstName:"Bob",FCDUserEmail:"test2@test.tst"}));
ClearCollect(ProfileData,{LastName:"Smith",FCDProfileEmail:"test@test.tst"});
ClearCollect(mergedData,AddColumns(DirectoryData,"LastName",LookUp(ProfileData,FCDUserEmail=FCDProfileEmail,LastName)))

 

The third line creates a new Collection called mergedData, populates it w/ the contents of DirectoryData + a new column that is a LookUp from ProfileData where the values between your two email columns FCDUserEmail and FCDProfileEmail match.

View solution in original post

jsantan73
Level: Powered On

Re: Merge one collection with another

Thank you, that worked!

jsantan73
Level: Powered On

Re: Merge one collection with another

It's one to one.  I guess I may have jumped the gun when I said it worked.  Is there a way to merge ALL the columns from both datasets based on the matching email column?

jsantan73
Level: Powered On

Re: Merge one collection with another

It's one to one.  I guess I may have jumped the gun when I said it worked.  Is there a way to merge ALL the columns from both datasets based on the matching email column?

jhall
Level 8

Re: Merge one collection with another

Now ask me how to do this if the two "lookup" columns were identically named.  Smiley LOL

 

HINT: Try the RenameColumns() function on your LookUp table input.

jhall
Level 8

Re: Merge one collection with another

Yes.  It's just adding some additional items to the LookUp.  The first item you add to the mergedList adds ALL COLUMNS from that table.  The LookUp then can add all of the columns from the secondary table.  You'd need to list them out though.  Let me pull up the LookUp function to make sure I've got the formatting correct and I'll post a followup.

jhall
Level 8

Re: Merge one collection with another

Yeah, it does get a little hairy w/ this as the solution.  It really depends on the use case of if this is a good way to handle it.  So if we stick w/ what I provided, then you pick the largest of the two Tables/Collections per field count and do that first (List1 in the example below).  Then add on each additional field manually into the list similarly to the blue text below.

 

This could get nasty fast, but there isn't a simple JOIN function within PowerApps (to my knowledge).  Kinda where maybe a SQL View or similar is a better solution to do outside of the application.

 

ClearCollect(
    mergedList,
    AddColumns(
        List1,
        "LastName",
        LookUp(
            List2,
            Email = Email2,
            LastName
        ),
       "NextField",
       LookUp(
            List2,
            Email = Email2,
            NextField
        )
    )
)

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 (5,098)