web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Automate
Answered

Filtering an array

(0) ShareShare
ReportReport
Posted on by 1,934 Moderator

An array that looks like this is the output of a select operation on the properties of a SharePoint library.

 

[
 {
 "Reviewer": "user.1@school.edu",
 "Filename": "file1.docx",
 "Reviewdue": "2021-11-17"
 },
 {
 "Reviewer": "user.1@school.edu",
 "Filename": "file2.docx",
 "Reviewdue": "2021-11-17"
 },
 {
 "Reviewer": "user.2@school.edu",
 "Filename": "file 3.docx",
 "Reviewdue": "2021-11-17"
 }
]

 

The array is the output of Select that has been sorted and stored in an array called sorted. Sorted has a length of 148.

An array variable called uniqueEmails is a union of the "Reviewer" item from the output of Select, producing a list of unique emails. uniqueEmails has a length of 20.

 

union(body('Select_emails'),body('Select_emails'))

 

Now, I need to make a HTML table for user.1 showing the 2 Filename and Reviewdue entries.

(Then the HTML table will go into an email addressed to the Reviewer address.)

Then, I want to make a HTML table for user.2 showing the 1 Filename and Reviewdue.

And so on sending an email and then looping through the list of uniqueEmails until the end.

annetoal_0-1667340229526.png

Item is 

item()

Reviewer is 

body('Select_emails')?['Reviewer']

Please help. This runs indefinitely and never finishes.

Thanks,

Anne

 

 

Categories:
I have the same question (0)
  • Verified answer
    grantjenkins Profile Picture
    11,063 Moderator on at

    You should only need the main Apply to each for the unique emails, and within that just have a:

    • Filter array
    • Create HTML table
    • Send email

    You don't need the two inner loops.

     

    So, for the first email it will filter the results by that email. You then create an HTML table from the Filter array. And finally send an email to that person with the HTML table in the email.

     

    The Filter array would use the output of sorted as its input, and you would then have the condition using:

    item()?['Reviewer'] Equal to Current Item from your Apply to each.

     

    I've created an example. The full flow is below. I'll go into each of the actions.

    grantjenkins_0-1667347647084.png

     

    Initialize variable sorted contains your array of JSON data.

    grantjenkins_2-1667347700156.png

     

    Select gets each of the Reviewer (emails) using the expression:

    item()?['Reviewer']

    grantjenkins_3-1667347765399.png

     

    Initialize variable unique emails uses a union to get unique emails.

    union(body('Select'),body('Select'))

    grantjenkins_4-1667347816093.png

     

    Apply to each iterates over each of the unique emails:

    grantjenkins_5-1667347844717.png

     

    Filter array usings sorted as its From and uses the expression for the Reviewer email.

    item()?['Reviewer']

    is equal to

    Current Item from the Apply to each. This will get the current email.

    grantjenkins_6-1667347976390.png

     

    Create HTML table uses the Body from Filter Array. I've just used Automatic Columns in this example.

    grantjenkins_7-1667348028365.png

     

    Send an email will then send an email to the current email address (Current item from Apply to each) with the embedded HTML table.

    grantjenkins_8-1667348086656.png

     

     

  • annetoal Profile Picture
    1,934 Moderator on at

    Thank you very much!

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Valantis Profile Picture

Valantis 411

#2
David_MA Profile Picture

David_MA 300 Super User 2026 Season 1

#3
Vish WR Profile Picture

Vish WR 291

Last 30 days Overall leaderboard