Skip to main content

Notifications

Power Automate - Building Flows
Answered

Merge 2 array bodies into single array using append to array variable in power automate

(0) ShareShare
ReportReport
Posted on by 75

Hello, 

 

I have 2 arrays resulting from 2 different 'Select' operation as below , I need to combine the output into single array for using it in looping later for each unique value in "Apply to each" step. 

 

I tried using "append to array variable ", but it does not merge the elements inside array.

Can you please let me know what I am missing here ? 

 

Sivaperumal31_1-1678326125983.png

 

Sivaperumal31_2-1678326170526.png

 

Sivaperumal31_3-1678326190105.png

 

Thank you 

 

  • Sivaperumal31 Profile Picture
    Sivaperumal31 75 on at
    Re: Merge 2 array bodies into single array using append to array variable in power automate

    Thank you @grantjenkins .

  • Verified answer
    grantjenkins Profile Picture
    grantjenkins 11,057 on at
    Re: Merge 2 array bodies into single array using append to array variable in power automate

    @Sivaperumal31 You can use the union expression to combine any number of arrays. Below is an example of how it works.

     

    //Will combine all arrays into a single array and remove any duplicate values
    
    union(array1, array2, array3, array...)

     

    See example below where I have three Selects similar to yours where we then use a union expression to combine them and remove any duplicate values.

    grantjenkins_5-1678366182527.png

     

    My three Selects have the following output. Note that "MY" Is listed twice so one of them will be removed when we apply the union expression.

    grantjenkins_6-1678366228108.png

    grantjenkins_2-1678366023775.png

    grantjenkins_3-1678366044845.png

     

    Compose uses the following expression to combine (union) the Selects and remove duplicate values.

    union(body('Select_1'), body('Select_2'), body('Select_3'))

    grantjenkins_7-1678366324754.png

     

    This would give the output below.

    grantjenkins_9-1678366403694.png

     

    Apply to each uses the output from Compose so it iterates over each of the items in the array.

    grantjenkins_8-1678366382912.png


    ----------------------------------------------------------------------
    If I've answered your question, please mark the post as Solved.
    If you like my response, please consider giving it a Thumbs Up.

  • Sivaperumal31 Profile Picture
    Sivaperumal31 75 on at
    Re: Merge 2 array bodies into single array using append to array variable in power automate

    Thank you @v-liwei-msft , It worked , I missed "Apply to each " before . 

    I assume I have to use another "Apply for each "  if I have to combine 3rd Array ? 

    Guess no other way to combine multiple array(3 or more ) other than using "apply to each" for every array to be appended .

  • Verified answer
    v-liwei-msft Profile Picture
    v-liwei-msft on at
    Re: Merge 2 array bodies into single array using append to array variable in power automate

    Hi @Sivaperumal31 

     

    I have made a test for your reference:

    1.

    vliweimsft_0-1678332328690.png

    2.

    vliweimsft_1-1678332403429.png

    3.

    vliweimsft_2-1678332433570.png

     

    Best Regards,

    Levi

     

     

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

Microsoft Kickstarter Events…

Register for Microsoft Kickstarter Events…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 145,434

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,722

Leaderboard