How to Merge Arrays in Power Automate? [With Different Examples]

Recently, during a product development, I faced a scenario where I had to combine data from multiple sources into a single array. In Power Automate, merging arrays is frequently needed when dealing with dynamic content like SharePoint lists, Excel rows, or API responses. Whether you’re aggregating data for reports, combining multiple lists, or preparing JSON payloads, merging arrays helps us organize your data efficiently.

I will show you how to merge arrays in Power Automate using different techniques in this tutorial. Whether you need to combine data from SharePoint lists, enhance arrays with additional details, or handle duplicates efficiently.

Merge Arrays in Power Automate

Follow the examples below:

Example: 1 [Combine Two Arrays of Data into a Single Array]

Imagine you are managing an Employee Training Program with two SharePoint lists i.e.:

  • Registered Employees: Stores employees who have signed up for training.
power automate merge two arrays
  • Waitlisted Employees: Stores employees on the same program’s waiting list.
power automate combine arrays

Now, I want to merge both lists into a single array and send an email notification containing the combined list of all employees (registered + waitlisted).

Now follow the below steps:

1. In the Power Automate, click the Instant Cloud flow, enter the Flow name, and choose the trigger flow (i.e., manually trigger a flow).

power automate combine two arrays

2. Add Initialize variable action and provide the below parameters to store Registered Employees SharePoint list value in an array format:

  • Name: Provide name as varRegisteredEmployees.
  • Type: Select type as Array.
  • Value: Leave as blank.
power automate merge arrays

3. Add Get items action and provide the below parameters to retrieve the Registered Employees SharePoint list value:

  • Site Address: Select your SharePoint site address.
  • List Name: Select your SharePoint list name.
power automate union two arrays

4. Next, add the ‘Apply to each’ action and provide the body output from the ‘Get items’ action. Inside the ‘Apply to each’ action, add the ‘Append to array variable’ action and use the following parameter:

  • Name: Select the above array variable.
  • Value: Provide below:
{
  "Employee Name": "@{items('For_each')?['EmployeeName']}",
  "Training Program": "@{item()?['TrainingProgram']}"
}
merge two arrays power automate

5. Again, add the Initialize variable action and provide the below parameters to store the Waitlisted Employees SharePoint list value in an array format:

  • Name: Provide name as varWaitlistedEmployees.
  • Type: Select type as Array.
  • Value: Leave as blank.
power automate left join two arrays

6. Add Get items action and provide the below parameters to retrieve the Waitlisted Employees SharePoint list value:

  • Site Address: Select your SharePoint site address.
  • List Name: Select your SharePoint list name.
power automate merge 2 arrays

7. Again, add the ‘Apply to each‘ action and provide the body output from the ‘Get items’ action. Inside the ‘Apply to each’ action, add the ‘Append to array variable’ action and use the following parameter:

concat array power automate

8. Then add a Compose action and provide the bellow expression to combine the above two arrays:

union(variables('varRegisteredEmployees'),variables('varWaitlistedEmployees'))
Power Automate Combine Two Arrays of Data into a Single Array

Now, click save and run the flow manually after it runs successfully. Click the compose action to see that the two arrays are combined.

[
  {
    "Employee Name": "John Doe",
    "Training Program": "Power Automate Basics"
  },
  {
    "Employee Name": "Jane Smith",
    "Training Program": "Power Apps Essentials"
  },
  {
    "Employee Name": "Alice Brown",
    "Training Program": "Power Automate Basics"
  },
  {
    "Employee Name": "Mike Johnson",
    "Training Program": "SharePoint Fundamentals"
  },
  {
    "Employee Name": "Tom Clark",
    "Training Program": "Power Automate Basics"
  },
  {
    "Employee Name": "Sarah White",
    "Training Program": "Power Automate Basics"
  }
]
Merge Arrays in Power Automate

Example: 2 [Merge Two Arrays to Create a Detailed Report]

Suppose you have two arrays, one with person names and the other with their ages. I want to create a single array containing complete details (ID, name, and age). The result will be formatted as an HTML table and sent via email.

Now follow the below steps:

1. In the Power Automate, click the Instant Cloud flow, enter the Flow name, and choose the trigger flow (i.e., manually trigger a flow).

Power Automate Merge Two Arrays to Create a Detailed Report

2. Add Initialize variable actions and provide the below parameters:

  • Name: varPersonName
  • Type: Array
  • Value:
[
  { "id": 1, "name": "John" },
  { "id": 2, "name": "Jane" },
  { "id": 3, "name": "Michael" }
]
power automate join array

3. Add Initialize variable actions and provide the below parameters:

  • Name: varPersonAge
  • Type: Array
  • Value:
[
  { "id": 1, "age": 30 },
  { "id": 2, "age": 25 },
  { "id": 3, "age": 40 }
]
join array power automate

4. Again, add Initialize variable actions and provide the below parameters:

  • Name: varPersonDetails
  • Type: Array
  • Value: Leave blank
power automate union 2 arrays

5. Add an Apply to each action to loop through the first array varPersonName:

  • Select an output from previous steps: Choose varPersonName from dynamic content.
@{variables('varPersonName')}
merge arrays power automate

6. Inside the loop, add a Filter array action to find the matching entry in the second array var

  • From: Select varPersonAge from dynamic content.
  • Condition:
    • Left Value: item()?[‘id’]
    • Operator: is equal to
    • Right Value: items(‘Apply_to_each’)?[‘id’]
power automate concat array

7. Add an Append to array variable action to merge the data:

  • Name: Select varPersonDetails from the dropdown.
  • Value:
{
"id": "@{item()?['id']}",
"name": "@{item()?['name']}",
"age": "@{first(body('Filter_array'))?['age']}"
}
power automate join 2 arrays

8. Add a Create HTML table action to generate a table from the merged array:

  • From: Select PersonDetails from dynamic content.
join arrays power automate

9. Add a Send an email (V2) action:

  • To: Provide the recipient’s email address.
  • Subject: “Merged Person Details Report”
  • Body: Select the output of Create HTML table from dynamic content.
combine arrays power automate

Save the flow and click the Test button. Select Manually to run the flow. Once the flow runs successfully, check your email to view the merged details in the HTML table.

Power Auotmate Merge Two Arrays to Create a Detailed Report

Example – 3 [Merge Two Arrays with XML Transformation]

In the above example, we saw how to merge using another array. Now, I will show you how to do the same using XML transformation. Follow the steps below to achieve this:

1. Follow the same first three steps to create an Instant Cloud Flow and choose ‘Manually trigger a flow.’ Add three ‘Initialize variable’ actions to define the arrays.

power automate combine 2 arrays

2. Add a Compose action to wrap the PersonAge array in a root element and provide the below:

{
  "root": {
    "Array": @{variables('varPersonAge')}
  }
}
power automate concatenate array

3. Add another Compose action to convert the output of the previous step into XML format:

xml(outputs('Compose'))
power automate merge arrays without apply to each

4. Add a Select action to merge the two arrays.

  • From: Select PersonName from dynamic content.
  • Map: Click on the T icon to switch to text mode, then provide the below code:
{
  "Id": @{item()?['id']},
  "Name": @{item()?['name']},
  "Age": @{xpath
(
  outputs('Compose_1'), 
  concat('//Array[id/text()="', item()['id'], '"]/age/text()')
)?[0]}
}
power automate append two arrays

5. Then add a Compose action and provide the above select action output from dynamic content.

append to array power automate

Now, click save and run the flow manually after it runs successfully. Click the compose action to see that the two arrays are combined.

[
  {
    "Id": 1,
    "Name": "John",
    "Age": "30"
  },
  {
    "Id": 2,
    "Name": "Jane",
    "Age": "25"
  },
  {
    "Id": 3,
    "Name": "Michael",
    "Age": "40"
  }
]
Merge Two Arrays with XML Transformation in Power Automate

Example – 3 [Joining Arrays While Keep Duplicates]

Here, I want to join two arrays while keeping duplicates intact using the convert-to-string and replace method in Power Automate. This method is efficient and avoids complex looping or conditions.

Now follow the below steps:

1. Log in to Power Automate and click +Create in the left navigation. Select Instant Cloud Flow, provide a name for the flow (e.g., ‘Join Power Platform Arrays with Duplicates’), and choose Manually trigger a flow. Then, click Create.

Power Automate Joining Arrays While Keep Duplicates

2. Add Initialize variable actions and provide the below parameters:

  • Name: varProductsGroup1
  • Type: Array
  • Value:
[
  "Power Apps",
  "Power Automate",
  "Power BI",
  "Dataverse",
  "AI Builder"
]
Join Power Platform Arrays with Duplicates

3. Add Initialize variable actions and provide the below parameters:

  • Name: varProductsGroup2
  • Type: Array
  • Value:
[
  "Power BI",
  "Power Pages",
  "Power Automate",
  "Power Virtual Agents",
  "Dataverse"
]
Joining Arrays While Keep Duplicates in Power Automate

4. Add a Compose action to merge the arrays using the below expression:

json(replace(concat(string(variables('varProductsGroup1')), string(variables('varProductsGroup2'))), '"]["', '","'))
  • string(variables(‘ProductsGroup1’)): Converts the first array into a string.
  • string(variables(‘ProductsGroup2’)): Converts the second array into a string.
  • concat(): Combines the two stringified arrays into a single string.
  • replace(): Replaces the ending/starting brackets (“][“) between the two stringified arrays with a comma and double quotes (“,”) to maintain the JSON array format.
  • json(): Converts the resulting string back into a valid array.
Join Power Automate Arrays with Duplicates

Save the flow, click Test, and manually run it after it runs successfully. Check the output of the Compose action.

[
  "Power Apps",
  "Power Automate",
  "Power BI",
  "Dataverse",
  "AI Builder",
  "Power BI",
  "Power Pages",
  "Power Automate",
  "Power Virtual Agents",
  "Dataverse"
]
 Joining Arrays While Keep Duplicates using Power Automate

Conclusion

In this tutorial, I covered various ways to merge arrays in Power Automate, including combining two SharePoint lists into a single array, merging arrays with additional details for reporting, using XML transformation to join arrays, and handling duplicates while merging arrays.

Related Power Automate tutorials:

>

Build a High-Performance Project Management Site in SharePoint Online

User registration Power Apps canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App

Power Platform Tutorial FREE PDF Download

FREE Power Platform Tutorial PDF

Download 135 Pages FREE PDF on Microsoft Power Platform Tutorial. Learn Now…