Showing results for 
Search instead for 
Did you mean: 
Helper IV
Helper IV

Working with Variables in Apply to Each

Hi all,


I think I should know this but I just can't get there.


I have 2 apply to each loops. In the 2nd loop, I'm appending to a string variable a name, I then get the outputs of this variable in the 'Compose' below it, which is outside the 2nd loop but still inside the first loop. I'm using append because if there's 3 names in the 2nd loop I want to append the 3 names together.


This works fine for the 1st loop, however, when the 1st loop moves on to the next value the append variable updates with more names - this I don't want!


What I'm looking to achieve is for the variable to store all the names from the 2nd loop but not all the names from the 1st loop - just the 2nd loop and reset for each 1st loop.


Maybe append to variable isn't the right approach here?


I hope that makes sense!





Super User
Super User

Hello @mccardj ,

you can use two string variable, one of them to use temporary.

So, you can append all the values to the temp variable, copy it in the def variable and clear the temp variable values.


In that way, you can grab only the names you want.


If I have answered your question, please mark my post as Solved.
If you like my response, please give it a Thumbs Up.



Helper IV
Helper IV

Hi @MarconettiMarco,


How do I go about clearing the temp variable values?


I thought it was as simple as setting the variable to null at the end of the flow but that didn't work - so I tried appending the variable to null and that didn't work either.


See the image below - the "Clear Participants" is setting the variable to null at the end of the flow but the variable is still appending across the 1st loop




Helpful resources

Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Community Calls Conversations

Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Users online (5,037)