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 / issue with variable in...
Power Automate
Unanswered

issue with variable in Apply to each loops

(0) ShareShare
ReportReport
Posted on by 431
I am building a Flow that collects items from three different Sharepoint lists and then composes a string of email addresses.
To compose the string of emails, I use an array variable.
My issue is, that if there are more than one Apply to each loop, the variable adds new addresses for every loop, with the end result that people are added to an email list where they shouldn't be.
What is the solution to this?
 
Edit for clarification:
  • I want to create one string of email addresses for each item that the "Get Items Emails To Send" delivers, with only the emails that belong to participants in the event that is connected to the "Get Items Emails To Send" item.
  • I will never know how many events that the "Get items Emails To Send" will deliver (in my example 2, resulting in 2 apply t o each loops - but there may be 1 or 576).
  • "Get items Event" will always get 1 item per "email to send" item.
  • I will never know how many items "Get items Participants" will deliver (in my example there are 2 different participants per event, but there may be 1 or 934)
 
This is a simplified version of the flow, with one extra compose action for testing.
 
This is the build.
 
And this is the FLow when there are two items in the "Get items Emails To Send" list.
 
Categories:
I have the same question (0)
  • Gyllentid Profile Picture
    894 on at
    What is your desired results?
     
    If you simply want to remove duplicates you can use the union() in expressions. Like union([insert the array]).

    If you need several arrays for different emails, use different arrays :)
  • MM-05080756-0 Profile Picture
    431 on at
    hi, i want separate email lists for each event.
    I do not know how to manage this with different arrays:
    • I will never know how many events that the "Get items Emails To Send" will deliver (in my example 2, resulting in 2 apply t o each loops - but there may be 1 or 576).
    • "Get items Event" will always get 1 item per "email to send" item.
    • I will never know how many items "Get items Participants" will deliver (in my example there are 2 different participants per event, but therea may be 1 or 934)
  • CU31011212-0 Profile Picture
    2 on at
    Can you just tell me what is the end objective?
    Are you doing this so you can later for example send emails?

    If you want that the addresses of the different iterations of the loops to be separated you should be probably be using a compose or setting the value of the array back to empty depending on your purpose.
  • creativeopinion Profile Picture
    10,502 Super User 2025 Season 2 on at
    @MM-05080756-0 It's extremely inefficient to run a Get Items action within an Apply to Each action. This will significantly slow down your flow. Instead, you'll want to run your Get Items actions outside of the Apply to Each loop and run them only once. Then, use a Filter Array action to filter out your items within your Apply to Each loop.
     
    If you aren't sure how to use the Filter Array action—check out these YT Tutorials:
     
     

    In this video tutorial I’ll show you 3 practical ways to use the Filter Array action and how to use it properly.
    1️⃣ Cross-Referencing Data
    2️⃣ Filtering by Key
    3️⃣ Substring Matching

    Did you know that the Condition action has a limit of 10 conditions? Although it might look like the Filter Array action can only accept one condition—this is not true. By using the advanced mode you can enter multiple conditions into a Filter Array action with an expression.

    IN THIS VIDEO:
    ✓ 3 Ways to Use the Filter Array Action
    ✓ How to use the Scope Action to Group Actions
    ✓ How to Check the Number of Items returned from a Filter Array Action
    ✓ How to Cross-Reference Data in Excel with a SharePoint List
    ✓ How the Filter Array Action Works
    ✓ How to Access the Dynamic Content from a Filter Array Action
    ✓ How to Filter Items by a Key
    ✓ How to Filter Items by Matching a Substring
    ✓ How to Use Multiple Conditions in a Filter Array Action

    ---

    In this tutorial—I’m going to show you a quicker way to get the dynamic content from your Filter Array action—and it doesn’t require writing an expression.

    IN THIS VIDEO:
    ✓ How to Loop Through Filter Array Results in Power Automate
    ✓ Using Apply to Each with Filtered Arrays
    ✓ The Easiest Way to Access Dynamic Content from Filter Array
    ✓ Fixing Nested Apply to Each Actions
    ✓ When to Use Value vs. Body Dynamic Content
    ✓ Simplifying Power Automate Flows with Filter Array
    ✓ Troubleshooting Filter Array and Apply to Each Issues

    ---

    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.

    IN THIS VIDEO:
    ✓ 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!

    Consider giving me a ❤️ if you liked my response!

    👉 Level up your Power Automate skills by checking out my tutorials on YouTube
    👉 Tips and Tricks on TikTok and Instagram
  • MM-05080756-0 Profile Picture
    431 on at
    The general opinion seems to be that my approach to the task is wrong (maybe even stupid?)
    So, let's start over.
     
    My task
    Send an email from a shared mailbox to all the participants in an event (BCC).
     
    The conditions
    1. Sharepoint list "Events". In this list, event hosts create event information. One list item/event. Column "Date and time" specifies the start date and time for the event. Event is identified with column "ID".
      • Number of events taking place at the same date or date/time vary.
    2. Sharepoint list "Participants". In this list, all participants in all events are listed (one item/person). The column "EventID" contains for every participant the ID of the corresponding event in "Events" list.
      • Number of participants vary between events.
    3. Sharepoint list "Emails". In this list, event hosts create items with the information that is to be sent to participants. Column "Date and time" specifies at which date and time the email is to be sent. The column "EventID" contains for every email the ID of the corresponding event in "Events" list.
      • Number of emails vary between dates.
      • Date to send email does not necessarily correspond with the date of the event.
      • Email content may include information from the corresponting item in "Events" list (i e event name from "Title" column, meeting link from "Link" column, and so on)
    My question
    What is the best approch to this?

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