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.

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.

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
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

SecondImage

PowerApps Monthly Community Call

Next Wednesday, August 21st at 8am PDT

Top Community Contributors for July 2019

Top Community Contributors for July 2019

Let's thank our top community contributors

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

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

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

FifthImage

Dynamics 365 and Power Platform April 2019 Release notes

Features releasing from April 2019 through September 2019!

SixthImage

Power Summit Australia 2019

August 20-23rd 2019

Users Online
Currently online: 184 members 4,096 guests
Please welcome our newest community members: