cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Martin_S
Regular Visitor

Merging two Arrays of objects

Hi

I am trying to merge two arrays of objects to one array.
The two arrays have one property in common that should be used to correlate the data correctly.
The arrays are not sorted in order and have different number of objects.

 

How do I combine the two arrays into to a single array with three properties using the ID property to correlate them correctly?

Br Martin Strandholm

Array 1:

[
{
"ID": "3333",
"Object_Name": "Power"
},
{
"ID": "1111",
"Object_Name": "Automate"
},
{
"ID": "2222",
"Object_Name": "Function"
}
]

 

Array 2:

 

[
{
"ID": "1111",
"Size": "5"
},
{
"ID": "2222",
"Size": "6"
},
{
"ID": "3333",
"Size": "8"
},

{
"ID": "4444",
"Size": "8"
}
]

1 ACCEPTED SOLUTION

Accepted Solutions
Paulie78
Super User
Super User

Hi @Martin_S,

 

It is an interesting question and something that comes up quite often. I've done a video for you which demonstrates a very efficient way of performing what you want to do.

 

https://youtu.be/QSF6dNkSKSA

 

Hope it helps.

 

Blog: tachytelic.net

YouTube: https://www.youtube.com/c/PaulieM/videos

If I answered your question, please accept it as a solution 😘

 

 

View solution in original post

5 REPLIES 5
ManishJain
Solution Sage
Solution Sage

Hi @Martin_S ,

 

Here is a nice article written for the same :

 

https://sharepains.com/2020/03/20/create-joins-in-power-automate/

 

Thanks

Paulie78
Super User
Super User

Hi @Martin_S,

 

It is an interesting question and something that comes up quite often. I've done a video for you which demonstrates a very efficient way of performing what you want to do.

 

https://youtu.be/QSF6dNkSKSA

 

Hope it helps.

 

Blog: tachytelic.net

YouTube: https://www.youtube.com/c/PaulieM/videos

If I answered your question, please accept it as a solution 😘

 

 

Thank you Paulie78.

 

I was trying with different ways of getting this done with good performance since the input will be a sharepoint list with a few thousand objects being combined with input from excel with about 600 objects.
When I tried doing it with Apply to each inside Apply to each it takes forever.

The way you did it was very clever and I will try to get it working.

 

Br Martin Strandholm

Hello

It is working nicely, except when one of the arrays is missing the id value.
Is there a way for the merge compose action to accept a null value in ID and continue?
Just adding the property accepting that the item()['ID'] is null?


addProperty(item(), 'Size', xpath(outputs('XML'), concat('//Array[ID/text()="', item()['ID'], '"]/Size/text()'))[0]) 

Change the expression to:

addProperty(item(), 'Size', xpath(outputs('XML'), concat('//Array[ID/text()="', item()?['ID'], '"]/Size/text()'))?[0])

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Power Automate Designer Feedback_carousel.jpg

Help make Flow Design easier

Are you new to designing flows? What is your biggest struggle with Power Automate Designer? Help us make it more user friendly!

Top Solution Authors
Users online (2,072)