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 / Stop loop when match n...
Power Automate
Answered

Stop loop when match not found

(0) ShareShare
ReportReport
Posted on by 71

I have a PAD that loops through an excel spreadsheet to find all records related to a specific email address and it then sends all records as an HTML table in one email.

 

This works fine when the excel sheet is small but if i test this with 3000+ records it would take to long.

 

The excel document is already sorted by email so would there be a way to stop cycling through the loop when the next record doesn't match and then move onto the next row or even speed up this PAD?

 

PAD.png

I have the same question (0)
  • RPGpro Profile Picture
    41 on at

    Given that the data is already sorted: 

    immediately  before the "for each current item" loop starts, initialise two new boolean variables as false. 

    immediately after the "for each current item" loop starts, start a if statement which checks if your first variable is false, move the rest of this loop into the if statement. add an else clause to this which sets both variables to false. 

     

    Add an else clause to the "email = current item" with 1 action: set first variable to equal the second variable. 

    Inside your existing if statement, set the second variable to true. 

     

    The end result: while cycling through the list, if it has not yet found a match, the loop will continue since both variables are still false. 

    Once it finds a result, one variable becomes true, the next time it fails to find a match the other variable becomes true and the loop skips to the next item. 

  • RR-27091314-0 Profile Picture
    71 on at

    @RPGpro thank you for your help, i believe i have followed your instructions but being very new to PAD i wondered if you could possibly double-check that i have implemented the additional code correctly?

     

    Untitled.png

  • RPGpro Profile Picture
    41 on at

    Close, just need to adjust the position of the first if statement (and hence its attached else statement) as per below.Untitled.png

  • RR-27091314-0 Profile Picture
    71 on at

    @RPGpro I appreciate you taking the time to look into this with me.

     

    I have made the changes you have highlighted but it now seems to be looping through the list and sending duplicate emails now, any ideas?

     

    Untitled.png

  • Verified answer
    RPGpro Profile Picture
    41 on at

    When the same email address appears multiple times in your data, do you want to send 1 email per appearance or append them all into 1 email and send that? 

    If you want to append them all into 1 then move the 3 commands that finalise and send the email into the else clause right above them

    Otherwise to avoid sending a duplicate one at the end, move them into the if statement immediately before the else starts. 

  • RR-27091314-0 Profile Picture
    71 on at

    This was the missing piece of the puzzle:

     

    If you want to append them all into 1 then move the 3 commands that finalise and send the email into the else clause right above them

     

    @RPGpro appreciate all the time and effort you put into helping me, thank you.

  • RR-27091314-0 Profile Picture
    71 on at

    @RPGpro after doing some testing i am still having some issues with the below.

     

    The PAD will loop through an excel document and correctly send one email each to email_1, email_2 and email_3 with all the relevant lines but email_4 wont recieve and email and email_5 recieves an email with only the table header, any ideas?

    rowan853_0-1675436892973.png

     

     

    Untitled.png

  • RPGpro Profile Picture
    41 on at
     but email_4 wont recieve and email 

    Double-check that it's an exact match to an entry in the email list. Other than this I can't see any issues with the logic.

     

    email_5 recieves an email with only the table header

    Totally forgot to factor in the last entry in the list, right near the start when you do "lastRow -1" for reading the data, remove the -1 so that there's an extra blank row that gets read in. 

     

    Edit: 

    The solution struck me right as I posted this response, replace the -1 with +1 instead. 

    It needs to loop thrugh at least 2 "miss" lines to set the variables and finish the email. So both the last and next-to-last will fail without having an extra 2 data rows in there. 

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
11manish Profile Picture

11manish 233

#2
David_MA Profile Picture

David_MA 217 Super User 2026 Season 1

#3
Valantis Profile Picture

Valantis 190

Last 30 days Overall leaderboard