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

Merge two collection

Hi Everyone,

 

How to merge two collection into one just like the Output Collection.

Example below. 

 

Capture123.JPG

Thank you in advance everyone 🙂 

 

Best Regards,

Boynogs123

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Merge two collection

Hi @Boynogs123 ,

Please try this formula:

ClearCollect(
    OutputCollection,
    Collect(
             RenameColumns(AddColumns(
                                      collection1,
                                      "EmpOutCode",
                                      LookUp(collection2,Code=collection1[@Code],EmpCode),
                                      "OutCode",
                                      LookUp(collection2,Code=collection1[@Code],Code)
                                     ),
                             "EmpCode","EmpInCode","Code","InCode"
                            ),
               RenameColumns(
                             Filter(collection2,Not(Code in collection1.Code)),
                             "EmpCode","EmpOutCode","Code","OutCode"
                             )
           )
         )

Firstly, combine collection2 with collection1 by using the same code that collection1 and collection2 both have.

Then collect the code that only collection2 has to the step1's collection.

 

 

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
Super User
Super User

Re: Merge two collection

@Boynogs123 

Table joins can be accomplished using the LookUp function

 

ClearCollect(
    OutputCollection,
    AddColumns(
        Collection1,
        "EmpCode",
        LookUp(Collection2,Code=Code[@Collection1],EmpCode),
        "Code",
        LookUp(Collection2,Code=Code[@Collection1],Code)
    )
)

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Boynogs123
Level: Powered On

Re: Merge two collection

Hi @mdevaney ,

 

The output will be like this.

Capture21.JPG

 

but there's a missing in collection 2 the 3a and 7a because they don't have a partner in collection 1

I want to get like this output.

123.JPG

 

Thank you for the reply@mdevaney  🙂

 

Best Regards,

Boynogs123

 

 

Super User
Super User

Re: Merge two collection

@Boynogs123 

As you noted in your previous post the problem here is Collection1 has no matching value to join on with Collection2 for 3a and 7a.  

 

There are two suggestions I have to solve this problem. 

 

#1 Include 3a and 7a in your Collection1 but do not fill-in any value for EmpInCode.

 

idea1.PNG

 

#2  My preferred way is to use only a single collection structured like this.  When the code arrives mark IN and when the code leaves mark OUT.

 

idea2.PNG

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

 

Boynogs123
Level: Powered On

Re: Merge two collection

Hi @mdevaney 

Maybe the #1 is okay.
How can I merge my 2 collection to get that output? 

Thank you for the response @mdevaney !

Best Regards,

Boynogs123

Super User
Super User

Re: Merge two collection

@Boynogs123 

As I said in my previous post 3a and 7a must be included in your Collection1 in order to merge.

Community Support Team
Community Support Team

Re: Merge two collection

Hi @Boynogs123 ,

Please try this formula:

ClearCollect(
    OutputCollection,
    Collect(
             RenameColumns(AddColumns(
                                      collection1,
                                      "EmpOutCode",
                                      LookUp(collection2,Code=collection1[@Code],EmpCode),
                                      "OutCode",
                                      LookUp(collection2,Code=collection1[@Code],Code)
                                     ),
                             "EmpCode","EmpInCode","Code","InCode"
                            ),
               RenameColumns(
                             Filter(collection2,Not(Code in collection1.Code)),
                             "EmpCode","EmpOutCode","Code","OutCode"
                             )
           )
         )

Firstly, combine collection2 with collection1 by using the same code that collection1 and collection2 both have.

Then collect the code that only collection2 has to the step1's collection.

 

 

Best regards,

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

Power Apps 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

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Solution Authors
Top Kudoed Authors (Last 30 Days)
Users online (2,865)