Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - Building Flows
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.

  • Robby_WW Profile Picture
    115 on at
    Re: Combining 2 arrays depending on values in both arrays

    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.

  • Verified answer
    Chriddle Profile Picture
    7,791 Super User 2025 Season 1 on at
    Re: Combining 2 arrays depending on values in both arrays

    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"
      }
  • creativeopinion Profile Picture
    10,439 Super User 2025 Season 1 on at
    Re: Combining 2 arrays depending on values in both arrays

    @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
     

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

Michael Gernaey – Community Spotlight

We are honored to recognize Michael Gernaey as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 566 Super User 2025 Season 1

#2
David_MA Profile Picture

David_MA 516 Super User 2025 Season 1

#3
stampcoin Profile Picture

stampcoin 492