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 / Combining 2 arrays dep...
Power Automate
Answered

Combining 2 arrays depending on values in both arrays

(0) ShareShare
ReportReport
Posted on by 115

Hey,

 

I have 2 arrays.

[{"Date": "2024-03-04", "Hours": 7},{"Date": "2024-03-05", "Hours": 4},{"Date": "2024-03-06", "Hours": 8}]

and

[{"Date": "2024-03-04", "Work": 7},{"Date": "2024-03-05", "Work": 5},{"Date": "2024-03-08", "Work": 6}]

 

result i would like to get is:

[{"Date": "2024-03-05", "Hours": 4, "Work": 5}, {"Date": "2024-03-06", "Hours": 8, "Work": 0}, {"Date": "2024-03-08", "Hours": 0, "Work": 6}]

 

Right now im using the following steps to get these results but its not very time friendly.

Robby_WW_0-1709562261703.png

is there another way to get these results?

Thanks.

Categories:
I have the same question (0)
  • creativeopinion Profile Picture
    10,502 Super User 2025 Season 2 on at

    @Robby_WW Can you switch to the Classic Designer and upload a screenshot where all the actions are expanded. It would help to provide more context. 

     

    In the meantime, the reason why your flow is taking a long time to run is due to the logic in your flow. Particularly the nested Apply to Each actions. 

     

    Take a look a this YT Tutorial I recently uploaded: 3 Mistakes YOU 🫵 are Making with the Apply to Each Action in your Microsoft Power Automate Flow

     

    In this video tutorial I’ll go over how to avoid these common mistakes when using the Apply to Each action in a Power Automate flow:

    1️⃣ Looping through a Single Item

    2️⃣ Creating Unnecessary Nested Loops

    3️⃣ Looping through an Unfiltered Array

     

    At the end of the video I share a few helpful insights when it comes to using the Apply to Each action in your flow.

    I'll also cover:

     

     How to avoid the Apply to Each action with a single item array

     How to use the item() function to access dynamic content in an array

     How to prevent unnecessary nested Apply to Each action loops

     How to use the Select action

     How to convert an array to a string with the Select action

    How to use the Filter Query field

     How to count the number of items in an array

     How to use a condition control

     How to use the concurrency control

     How to set a top count

     How to use Compose actions for troubleshooting

     

    Hope this helps!

    If I helped you solve your problem—please mark my post as a solution .
    Consider giving me a 👍 if you liked my response! If you're feeling generous— ️  Buy me a coffee: https://www.buymeacoffee.com/acreativeopinion

    👉 Watch my tutorials on YouTube
    👉 Tips and Tricks on TikTok
     

  • Verified answer
    Chriddle Profile Picture
    8,441 Super User 2025 Season 2 on at

    Chriddle_0-1709564449585.png

    Select

    From

    union(
    	xpath(
    		xml(json(concat('{"Root":{"Item":', union(outputs('Array0'), outputs('Array1')), '}}'))),
    		'//Date/text()'
    	),
    	json('[]')
    )

    Map Date

    item()

    Map Hours

    coalesce(
    	first(
    		xpath(
    			xml(json(concat('{"Root":{"Item":',outputs('Array0'), '}}'))),
    			concat('//Item[Date="', item(), '"]/Hours/text()')
    		)
    	),
    	0
    )

    Map Work

    coalesce(
    	first(
    		xpath(
    			xml(json(concat('{"Root":{"Item":',outputs('Array1'), '}}'))),
    			concat('//Item[Date="', item(), '"]/Work/text()')
    		)
    	),
    	0
    )

     

    Result

    [
     {
     "Date": "2024-03-04",
     "Hours": "7",
     "Work": "7"
     },
     {
     "Date": "2024-03-05",
     "Hours": "4",
     "Work": "5"
     },
     {
     "Date": "2024-03-06",
     "Hours": "8",
     "Work": 0
     },
     {
     "Date": "2024-03-08",
     "Hours": 0,
     "Work": "6"
     }
    ]

     

    Why is this not part of your expected result?

    {
        "Date""2024-03-04",
        "Hours""7",
        "Work""7"
      }
  • Robby_WW Profile Picture
    115 on at

    Its not so much of "expected". its to already filter out data to see if certain dates have hours and work isn't equal.

     

    Thank you, with this i can improve my flow a lot.

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