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 Platform Community / Forums / Power Automate / How to do a foreach on...
Power Automate
Unanswered

How to do a foreach on unique values from a SP list

(0) ShareShare
ReportReport
Posted on by 4

Hello,

 

I have managed to retrieve the content of a SP list, which looks something like this:

ID | Customer Name | Assigned person

1 | Customer 1 | Bob

2 | Customer 2| Bob

3 | Customer 3 | Jack

4 | Customer 4 | Jack

 

What I would like to do is send a single email (every two week for example) to each "Assigned person" with the list of all the opportunities assigned to him. Eg.:

Bob will receive an email with the information regarind Customer 1 & Customer 2.

Jack will receive an email with the information regarding Customer 3 & 4.

 

I have tried the following flow:

Recurrence > Get Items > Create HTML Table > Send Email

 

This works fine, but I'd like to send only the relevant information to the right people in "Assigned person".

 

Any thoughts?

Categories:
I have the same question (0)
  • Meneghino Profile Picture
    6,949 on at

    Hi @Luigi312

    I would suggest nested apply to each loops:

    1) An outer loop for each assigned person

    2) An inner loop that threads through the opportunities for that person and composes a single email text

    Please let me know if you need details

     

    PS Here is a reference:

    https://flow.microsoft.com/es-es/blog/nested-apply-to-each/

  • Luigi312 Profile Picture
    4 on at

    Thank you @Meneghino

     

    The issue is: I can't do an Apply to each with other values than the Sharepoint lists items, or the entire Output of a "Select". I can't do an Apply to each on single items. Eg. : Apply to each "Leader" 

     

    So I've ended up with this, but this doesn't work ...

     

  • Meneghino Profile Picture
    6,949 on at

    OK, there are two possible alternative approaches:

    1. Add another 'Get items' step which will get the items grouped by Leader, so that you can have a list of leaders that you can iterate through for the outer loop. Please note that the send email should be outside the inner loop but inside the outer loop, since you want to send only one email per leader
    2. Use only one 'Apply to each' loop, but use a variable to keep track of the current Leader.  If the leader changes, then you send the email and reinitialise the variables.  In this case your 'Get items' step will need to get the items ordered by Leader

    Please let me know if anything is unclear

  • Luigi312 Profile Picture
    4 on at

    I couldn't make it work. Tried everything. I am giving up.

     

    Thanks for your time and patience.

  • Meneghino Profile Picture
    6,949 on at

    It can be done, please Skype me to discuss.

    Skype is baizini

  • Meneghino Profile Picture
    6,949 on at

    PS What type of column is customer? (text, choice or lookup)

    What type of column is Assigned person? (person, text, choice, or lookup)

  • anhthuch4ng Profile Picture
    Microsoft Employee on at

    Hi @Luigi312 and @Meneghino,

     

    We you two able to meet on Skype to discuss a solution to this?

    Hoping that conversation was helpful,

     

    -AT

  • Meneghino Profile Picture
    6,949 on at

    Yes, we did, thank you.  It was resolved, I believe.  Flow is a very good product, much more robust than PowerApps.

  • TwoPuttTommy Profile Picture
    9 on at

    Can you post the solution on this board?  I'm having the same problem and can't figure this out.

     

    Thanks! 

  • Meneghino Profile Picture
    6,949 on at

    Basically:

    1. Initialise Email body variable with nothing
    2. Get the items
    3. Initialise the OldAddressee variable with the first item
    4. For each of the items
      1. If this item=last item or CurrentAddressee<>OldAddressee
        1. then
          1. If this item=last item add current item content to Email body else nothing
          2. Send email to OldAddressee with Email message
          3. Clear Email body variable
          4. Set OldAddressee=CurrentAddressee
        2. else nothing
      2. Add current item content to Email body

     

     

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 Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 262 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 167

#3
Haque Profile Picture

Haque 154

Last 30 days Overall leaderboard