web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Merging Two Collection...
Power Apps
Answered

Merging Two Collections and Retaining ALL Columns?

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

What is the best method to merge these two collections and retain ALL columns?  The two collections are joined via the deal id which is "Title" in colDashDealIntakeApp and "Deal_x002d_Ref_x002d_ID" in colDashDealUpdates.

ClearCollect(colDashDealIntakeApp, ShowColumns('Deal-Intake-App', "Title", "Close_x002d_Date")); 
ClearCollect(colDashDealUpdates, ShowColumns('Deal-Updates', "Deal_x002d_Ref_x002d_ID", "Pursuit_x002d_Closedown_x002d_Da"));

 

Categories:
  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    Hi @Anonymous 

    You could use the AddColumns() function to create the final merged collection

     

    ClearCollect(colDashDealIntakeApp, ShowColumns('Deal-Intake-App', "Title", "Close_x002d_Date")); 
    ClearCollect(colDashDealUpdates, ShowColumns('Deal-Updates', "Deal_x002d_Ref_x002d_ID", "Pursuit_x002d_Closedown_x002d_Da"));
    
    With({cddia:colDashDealIntakeApp, 
     cddu:colDashDealUpdates,
     dealID:"Deal_x002d_Ref_x002d_ID",
     pursuitclosed:"Pursuit_x002d_Closedown_x002d_Da"},
     ClearCollect(
     colAll,AddColumns(
     cddia,"DealUpdates", Lookup(
     cddu,dealID = "Title",'Deal-Updates'
     ),
     "PursuitCloseDown", Lookup(
     cddu,"dealID= "Title",pursuitclosed
     )
     )
     )
    )

     

    This assumes that the first two collections actually exist. The merged collection would be colAll.  The With() function is used to clean up your collection names and fields.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @Drrickryp - Thanks for the response. Unfortunately, AddColumns has some invalid code.  Any recommendations? 

    JOIN 2 Collections.PNG

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @Anonymous 

    My code makes assumptions about your collections. I revised it to try to make it less likely to have typos.  However, could you put a couple of datatables on a screen and set the Items property to the two collections  you are trying to merge so that I can get a better idea about your data?

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    This what the data looks like.  The bold header text is not the actual col names.  "PCDate" = "Pursuit_x002d_Closedown_x002d_Da".

    JOIN 2 Collections 2 tables.PNG

  • Verified answer
    Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    The principle behind merging the collections is to use the AddColumns() function to create a new column in one of the collections. So starting with the first collection, first you give the new added column a "name", then you use Lookup() on the second collection to match the common fields, and then select the column in the second collection that you want to add to the first collection. The syntax is

    AddColumnsTable, "ColumnName1"Formula1 [, "ColumnName2"Formula2, ... ] ) 

    where in your case, the table is a collection, the second element is a new name you will give to the added column and the formula is a Lookup(Table2, Deal-ID=Title, PCDDate) which looks up in a second collection for a row that matches the dealID to the title, and then adds the column from the second table. 

    It appears that you are using SharePoint and I suggest that you review https://www.practicalpowerapps.com/data/constructing-your-first-power-app-before-you-start/ 

    The way you have constructed your lists makes it extremely difficult to work with them.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @Drrickryp  - Thanks for the great explanation of merging collections! I agree about my mistake with the column names. 

    It looks like you edited your original proposed solution so I ran the updated version.  I am getting error "AddColumns has some invalid arguments".  It looks like you are using aliases to make references easier.  Any recommendations on how to fix this are greatly appreciated.  

    JOIN 2 Collections II.PNG
     
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 381 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 340

#3
WarrenBelz Profile Picture

WarrenBelz 187 Most Valuable Professional

Last 30 days Overall leaderboard