Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Outlook
    • Planner
    • Power Apps
    • SharePoint
    • Teams
  • Triggers
  • Ready to use solutions
    • Approval Process Template
    • Task Delegation App
    • The Ultimate Power Automate expressions cheat sheet
    • Power Automate HTTP requests to SharePoint cheat sheet
    • Power Automate HTTP requests to Graph API cheat sheet
  • ABOUT ME
  • Get help with your flow
  • POWER PLATFORM SERVICES
Menu

Turn two arrays into one through a shared value with Power Automate

Posted on July 6, 2022July 12, 2022 by Tom

“I’ve got two arrays with various user information, can I use Power Automate to merge the arrays into one array with all the information?”


If you’ve got all the information you need in a single data source, you’ll get an array of objects with everything. But what if it’s not in a single data source? If you’ve got multiple data sources, e.g. multiple SharePoint lists or Excel files? Each of them might contain a specific piece of the information you need.

But that’ll give you multiple arrays, and working with multiple arrays is not the easiest thing to do. Could it be easier to turn it all into a single array?

Get all the arrays

The prerequisite for the solution is a shared value. If you’ve got two or more arrays with values you must know which values belong to each other.

Let’s use the ‘Name’ property as the connector, but it can be any property you’ve got.

First array
[
    {
        "Name": "Tom",
        "Country": "CZ"
    },
    {
        "Name": "Paul",
        "Country": "UK"
    }
]

Second array
[
    {
        "Name": "Tom",
        "Age": "younger than Paul"
    },
    {
        "Name": "Paul",
        "Age": "older than Tom"
    }
]

Turn them into a single array

Since the result should be a single array, the next step is to initialise an array variable. You’ll use it to store the new, merged array. Let’s call it ‘var_finalArray’.

Merging two arrays is very similar to comparing two arrays. It takes a loop to process all the entries in the first array and a ‘Filter array’ action to find the corresponding entry in the second array. Since here you’re working with two custom arrays, you must select the values to compare directly with an expression.

There’re two ways to select them:

item()?['property'] 
or 
items('loop_name')?['property']

If you use item()?[‘property’] = item()?['Name'] you’re referencing the input of the action, on the screenshot below it’s the input of the ‘Filter array’. But to access the currently processed item from the loop you must use items(‘loop_name’)?[‘property’] = items('Apply_to_each')?['Name'].

Make sure that you use the right expression to reference the right array!

Power Automate two arrays into one

The filtered result should be just a single object from the second array, connected to the currently processed one. As such you can use its values to build the new, merged array.

Again, you must be careful to use the right reference! If it’s a value from the first array (the one you use in the ‘Apply to each’), reference the values by:

item()?['property']

If it’s from the second array (the filtered one), you must reference it as the output from the ‘Filter array’. And since there should be only a single result, use the first(…) expression to get the sole result:

first(body('Filter_array'))?['property']
Power Automate two arrays into one

At the end of the loop you’ll have the merged array in the variable.

Summary

You can use Power Automate to turn two arrays into one as long as there’s a shared value connecting the arrays. Once you have such value you can loop through the first array, look for the corresponding entry in the second array, and store the values in a variable. And if there’re more than two arrays you can merge the arrays one by one while repeating the process.

The solution above might get slow with bigger data sets, if your array has hundreds or thousands of items check Paul’s solution.


πŸš€ Master Power Automate

Join 2,000+ professionals getting actionable Power Automate tutorials, solutions, cheat sheets & tips every week.

No spam. Unsubscribe anytime.

4 thoughts on “Turn two arrays into one through a shared value with Power Automate”

  1. Dan says:
    August 3, 2022 at 9:27 am

    That’s impressive!

    Reply
  2. Adediran David Adedapo says:
    May 13, 2023 at 10:33 pm

    Hello Tom.
    I know Paul’s solution is faster for larger data sets but it you want to make your solution more efficient, you can use a compose instead of the array variable.
    Compose in a array has the advantage of not messing up if the concurrency is turned on for the Apply to each loop.
    And it can be accessed outside of the loop as an array.

    Reply
    1. Tom says:
      May 28, 2023 at 3:18 pm

      Hello Adediran,
      thank you for the comment, you’re right, ‘Compose’ could make many of the flows here even faster.

      Reply
  3. David Darbant says:
    May 21, 2024 at 9:46 pm

    Tom,
    Was struggling with this for a full day until I saw your post. Very nice!

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

πŸš€ Master Power Automate

Join 2,000+ professionals getting actionable Power Automate tutorials, solutions, cheat sheets & tips every week.

No spam. Unsubscribe anytime.

Working on an Approval process?

Use the Approval Process Template and the Task Delegation App to skip the hard part and deploy a fully functional approval solution on a SharePoint list in minutes! And then the next one, and the next one...

Approval Template Preview ✨ Learn more ✨

Turn ideas into flows with ease!

Grab the complete Power Automate Cheat Sheet Bundleβ€”everything you need to master expressions, SharePoint HTTP calls, and Graph API in Power Automate.

Cheat Sheet Bundle Preview ✨ Get the Cheat Sheets

Didn't find what you were looking for?
Need to adjust a solution to fit your needs?
Or would you just like to get an assistance from somebody with thousands of hours of experience with Power Automate?

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2025 Let's POWER Automate | Theme by SuperbThemes