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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Merging two Arrays of ...
Power Automate
Unanswered

Merging two Arrays of objects

(2) ShareShare
ReportReport
Posted on by

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"
}
]

Categories:
I have the same question (0)
  • MJain Profile Picture
    2,450 on at

    Hi @Anonymous ,

     

    Here is a nice article written for the same :

     

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

     

    Thanks

  • Verified answer
    Paulie78 Profile Picture
    8,422 Moderator on at

    Hi @Anonymous,

     

    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 😘

     

     

  • Community Power Platform Member Profile Picture
    on at

    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

  • Community Power Platform Member Profile Picture
    on at

    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]) 

  • Paulie78 Profile Picture
    8,422 Moderator on at

    Change the expression to:

    addProperty(item(), 'Size', xpath(outputs('XML'), concat('//Array[ID/text()="', item()?['ID'], '"]/Size/text()'))?[0])
  • svivek Profile Picture
    65 on at

    Hi,

    I applied above solution in my case which is:

    I need to merge following arrays:

    Array 1:

    [
      {
        "Parameter""2A",
        "No Match Array 1""40"
      }
    ]
     
    Array 2:
    [
      {
        "Parameter""2A",
        "No Match Array 2""80"
      }
    ]
    I require final array as
    [
      {
        "Parameter""2A",
        "No Match Array 1""40"
         "No Match Array 2": "80"
      }
    ]
     
     
    For this I created following flow. Here both arrays are coming from select operation:
    svivek_0-1658367910556.png

     

    However I am getting following error . Pls advice where am I going wrong. 

     

    svivek_1-1658370008288.png

     

  • Paulie78 Profile Picture
    8,422 Moderator on at

    You need to use the output of the action Root for XML as the inputs for the XML action. You have used No_match_Array_1_Table

  • svivek Profile Picture
    65 on at

    Hi @Paulie78 

    Thanks for above response it rectified the problem . However the final output value for one item is coming as null. Pls advice.

     

    Following expression used:

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

     

    Following is the flow:

     

    svivek_5-1658400510493.png

     

     

    Output of No match array table 2:

    svivek_4-1658400293889.png

     

     

     Output of No match array table 1:

     

    svivek_2-1658399931442.png

     

     

     

    Final output:
    svivek_0-1658399793656.png

     

  • svivek Profile Picture
    65 on at

    Hi @Paulie78 

     

    Thanks for your solution. However I am having one additional query. Kindly help.

     

    Your solution added size for ID: "1111", "2222" and "3333". 

    However the fourth ID "4444" is NOT showing in the final result. Pls let me know if there is any way to have ID "4444" also included with size as final result as mentioned below:

    Like below:

     

    "ID": "4444",
    "Object_Name": "Null"

    "Size": "8"

  • 20Nails Profile Picture
    2 on at

    Try to duplicate the steps.

    -Just add a PrepareArray1 action:
    {
    "root": {
    "Array": @{outputs('Array1')}
    }
    }

    -Add a XML2 action with the ouputs of the PrepareArray1 action.
    xml(outputs('PrepareArray1'))

    -Then add a parallel branch and a Select2 action to add the property present in Array1 that is missing in Array2 (in this case, the Object_Name property):
    FROM: outputs('Array2')
    MAP: addProperty(item(), 'Object_Name', xpath(outputs('XML2'), concat('//Array[ID/text()="', item()?['ID'], '"]/Object_Name/text()'))?[0])

    -Then, add a compose action to union both select1 and select2
    union(outputs('Select'),outputs('Select2')

    This step will merge both arrays without duplicates.

    Here the complete flow.

    Part1Part1

     

    Part2Part2

     




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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 523 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 406 Moderator

#3
abm abm Profile Picture

abm abm 245 Most Valuable Professional

Last 30 days Overall leaderboard