Skip to main content

Notifications

Community site session details

Community site session details

Session Id : XLtohj2XRfvfCb+1ibirx7
Power Automate - Building Flows
Answered

How to combine two arrays?

Like (0) ShareShare
ReportReport
Posted on 7 Nov 2023 13:44:36 by 1,095

I have two arrays

 

 

[
 {
 "CustomerName": "Customer A",
 "CustomerId": "1",
 "CustomerPersonId": "1",
 "CustomerPersonName": ""
 },
 {
 "CustomerName": "Customer B",
 "CustomerId": "2",
 "CustomerPersonId": "1",
 "CustomerPersonName": ""
 },
 {
 "CustomerName": "Customer C",
 "CustomerId": "3",
 "CustomerPersonId": "2",
 "CustomerPersonName": ""
 }
]

 

 

And

 

 

[
 {
 "PersonName": "PersonName 1",
 "PersonId": "1"
 },
 {
 "PersonName": "PersonName 2",
 "PersonId": "2"
 }
]

 

 

 

I want to create an array in power automate that looks like this

 

[
 {
 "CustomerName": "Customer A",
 "CustomerId": "1",
 "CustomerPersonId": "1",
 "CustomerPersonName": "PersonName 1"
 },
 {
 "CustomerName": "Customer B",
 "CustomerId": "2",
 "CustomerPersonId": "1",
 "CustomerPersonName": "PersonName 1"
 },
 {
 "CustomerName": "Customer C",
 "CustomerId": "3",
 "CustomerPersonId": "2",
 "CustomerPersonName": "PersonName 2"
 }
]

 

 

So the thing that i want is to do a lookup on customerpersonId and get the name of that person and add that to the first array.

 

I would prefer not to be forced to use variables since i have many rows to update and want to make it quick. I tend to belive that using vriables does not allow a for each loop in power autoamte to be that fast.

 

 

 
  • ManishSolanki Profile Picture
    15,085 Super User 2025 Season 1 on 08 Nov 2023 at 07:05:06
    Re: How to combine two arrays?

    Hi @Oskarkuus 

     

    The idea is to convert the JSON into XML & using xpath query we can filter required value from xml node. The same concept applies to html also.

     

    You can check out my blog where I have explained with a use case:

    Power Platform Join arrays efficiently without using loops in Power Automate Select (technetty.com)

     

     

    If this helps & solves your problem, please remember to give a 👍 and accept my solution as it will help others in the future.

     

    Thanks

  • Kaif_Siddique Profile Picture
    2,104 Super User 2024 Season 1 on 08 Nov 2023 at 06:41:35
    Re: How to combine two arrays?

    Hi,

     

    sharing another solution:

     

    Flow:

     

    Kaif_Siddique_1-1699425157749.png

     

    Kaif_Siddique_5-1699425629974.png

     

    Kaif_Siddique_2-1699425172085.png

     

    Kaif_Siddique_3-1699425182276.png

     

    Filter array

    PersonId item()?['PersonId']
    CustomerPersonId items('Apply_to_each')?['CustomerPersonId']

     

    Append to array variable

    CustomerName @{items('Apply_to_each')?['CustomerName']}
    CustomerId @{items('Apply_to_each')?['CustomerId']}
    CustomerPersonId @{items('Apply_to_each')?['CustomerPersonId']}
    CustomerPersonName first(body('Filter_array'))?['PersonName']

     

    Output:

    Kaif_Siddique_4-1699425468618.png

     

    Regards

    Kaif

  • Oskarkuus Profile Picture
    1,095 on 07 Nov 2023 at 19:35:31
    Re: How to combine two arrays?

    This method is amazing. I am a bit annoyed over that i can not figure out what it does tho 😛

     

    Do you mind explaining this:


    xpath(xml(json(concat('{"Root":{"Item":',outputs('Compose_2'),'}}'))),concat('string(//Root//Item/PersonId[text()=','''',item()?['CustomerPersonId'],'''',']/../PersonName/text())'))

     

     

  • Verified answer
    ManishSolanki Profile Picture
    15,085 Super User 2025 Season 1 on 07 Nov 2023 at 14:45:55
    Re: How to combine two arrays?

    Hi @Oskarkuus 

     

    Here is the sample flow. I have stored both the arrays in compose actions:

    ManishSolanki_0-1699367868600.png

    ManishSolanki_1-1699367885345.png

     

    Next, add Select action and pass the output of compose action in "From" parameter. For each value of key in Map parameter, expression needs to be added:

    ManishSolanki_2-1699368050672.png

    Expression needs to be entered in the expression box as highlighted in the above screenshot.

    Key Value
    CustomerName
    item()?['CustomerName']
    CustomerId
    item()?['CustomerId']
    CustomerPersonId
    item()?['CustomerPersonId']
    CustomerPersonName
    xpath(xml(json(concat('{"Root":{"Item":',outputs('Compose_2'),'}}'))),concat('string(//Root//Item/PersonId[text()=','''',item()?['CustomerPersonId'],'''',']/../PersonName/text())'))

     

    The output of select action will give the desired array:

    ManishSolanki_3-1699368276876.png

     

    If this helps & solves your problem, please remember to give a 👍 and accept my solution as it will help others in the future.

     

    Thanks

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,670 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,004 Most Valuable Professional

Leaderboard
Loading started