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 / how to peek at next it...
Power Automate
Unanswered

how to peek at next item in an apply to all loop

(0) ShareShare
ReportReport
Posted on by

I am looking to find a simple way to see the "next" item in an apply to all loop I use to iterate through a sorted list that I get from the List rows in table action.

 

My overall log is:

1) Get table that has user's column sorted by user

2) Apply to each item in the table

2.1) append value to a emailBody string

2.2) if user from next item in the loop is (different than current item) or (empty), send the email; Otherwise, do nothing

2.3) end loop

 

My problem is I can't seem to find an easy way to get the next item in the loop. I have worked on several variants of the loop with similar logic but it either clutters up the flow (with too many checks/updates for if previous = current logic) or introduces undo inefficiencies by using a filter that internally loops through the table on each call within the outer loop.

 

My goal is to build the list as I iterate through the list but keep the logic easy to follow. The logic to loop up and send an email could be a little invloved since I need to handle invalid user found and do lookups for a back up email address so if I can block out this code with a simple if statement, it would be easier to maintain and follow. maintaining a previous item variable seems to cloud up the logic. 

 

If there are any suggestion on how to look at the next item in the loop, please share. I noticed there is a "skip()" function that may help, but I do not know how to pass in the index value of an "apply to" loop.

 

Sorry for the long explaination. I am hoping there is an easy answer or technique here.

 

Thanks

 

 

 

 

Categories:
I have the same question (0)
  • Verified answer
    RezaDorrani Profile Picture
    12,143 on at

    Hi @Anonymous 

     

    Before for loop, initialize a variable of type number and set its value to 0 (this will be used to drive the index of the item)

     

    Next within the loop

    the expression item() will give you context to the current running item

    If you need to read  a particular property you can use

    item()?['columnname'] to get its value

     

    Now to peek into next item

    You can use the following expression

     

    first(skip(dynamiccontentcollection,add(variables('counter'),1)))
    where dynamiccontentcollection - is the dynamic content value of the collection being looped
    This will give you the next item
    If you want to read a particular property of next item
    use expression first(skip(dynamiccontentcollection,add(variables('counter'),1)))?['columnname']
     

    Regards,

    Reza Dorrani

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

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 538 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard