Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Planner
    • Outlook
    • SharePoint
    • Teams
  • Triggers
  • Resources
  • ABOUT ME
  • Get help with your flow
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.


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

1 thought 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

Leave a Reply Cancel reply

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

Do you know what to do, but not how to do it?

Get The Ultimate Power Automate expressions cheat sheet and translate your thoughts into flows with ease!


There's also the HTTP requests to SharePoint cheat sheet to help you overcome limitations of some standard actions!

Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

  • How to find Excel rows missing in SharePoint list (Power Automate)March 29, 2023
  • Check whether user exists in AAD with Power AutomateMarch 26, 2023
  • How to highlight whole SharePoint row based on calculated dateMarch 22, 2023
  • Why is your Power Automate flow running so slow?March 19, 2023
  • How to add multiple links to the Power Automate approval taskMarch 15, 2023

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2023 Let's POWER Automate | Theme by SuperbThemes