cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

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
Continued Contributor
Continued Contributor

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
Drrickryp
Super User
Super User

Hi @Anonymous 

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

jhall
Continued Contributor
Continued Contributor

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

Anonymous
Not applicable

Thank you, that worked!

Anonymous
Not applicable

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?

Anonymous
Not applicable

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
Continued Contributor
Continued Contributor

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
Continued Contributor
Continued Contributor

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
Continued Contributor
Continued Contributor

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
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (2,177)