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 / How to combine two arr...
Power Automate
Answered

How to combine two arrays?

(0) ShareShare
ReportReport
Posted on by 1,097

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.

 

 

 
Categories:
I have the same question (0)
  • Verified answer
    ManishSolanki Profile Picture
    15,091 Super User 2025 Season 2 on at

    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

  • Oskarkuus Profile Picture
    1,097 on at

    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())'))

     

     

  • Kaif_Siddique Profile Picture
    2,108 Super User 2024 Season 1 on at

    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

  • ManishSolanki Profile Picture
    15,091 Super User 2025 Season 2 on at

    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

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 503 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 321 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard