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 / Loop inside a for each
Power Automate
Answered

Loop inside a for each

(0) ShareShare
ReportReport
Posted on by 17

Currently, I can look up each district using my PA Flow, but instead of searching for Clinton Community for each record, I would like to learn how to loop through the three records for Clinton Community without going through the search steps in my flow. Once I have found Clinton Community, I can add the three records using my "for each" loop.

 

I need a way to store the previous currentItem in a variable for use in the next for each loop. This is the part I need some help figuring out.

 

Delta

 

2023-02-21_15-54-05.png

2023-02-21_15-33-38.png

  • MichaelAnnis Profile Picture
    5,727 Moderator on at

    so, I’m a little confused, but I’ll give you an example, and if it’s the opposite of that, I’m sure you will get it. 

    for each %currentitem% in %list%
        if %currentitem% = %previousitem%

            Next ‘this command goes to the next for each

        End(IF)

    ’here is all the rest of your actions in the for each

    Set %PreviousItem% to %CurrentItem%

    End (For Each)

     

    you want to set previous item at the end of your for each statement, so current item doesn’t change it unless you want it to. In the case of the IF statement being true, you don’t need to change it, because it was the same as before. 

    good luck!

  • dsmith2006 Profile Picture
    17 on at

    Thank you @MichaelAnnis I have my flow looping the first and second instances of each item for a district. When it comes to the third item for a district, it is jumping out of the AddNewCommitteeMember and going straight to FindDistrictCommittee. In the loom video at 3:04, it shows it jumping to FindDistrictCommittee. Because there is a third item for the district, it should go to the main flow, evaluate that the PreviousDistrict = CurrentDistrict, and go to AddNewCommitteeMember.

     

    Would you please help me figure out what I am missing that this is not going back to the Main Flow

  • Verified answer
    MichaelAnnis Profile Picture
    5,727 Moderator on at

    Sorry it took a while. Been a busy week.

     

    you did great. You just need a “Next” before the “End” of your IF statement. 

    Without next, it’s going to continue through. 

    so round one, it skipped the if (cuz it didn’t match). 

    round two, it processed the IF, and added member number 2 correctly, but then you didn’t tell it to go to “Next”, so it continued on after the IF and tried to find the district again. 

    by adding “next”, it skips all remaining steps in the loop (or for each) and starts the next iteration. 

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

Leaderboard > Power Automate

#1
11manish Profile Picture

11manish 315 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 267

#3
Henil Profile Picture

Henil 115

Last 30 days Overall leaderboard