Loops – it existed since the inception of programming and it’s there in all languages and platforms. And why then Power Automate shall be an exception?
Power Automate too has the ‘Apply to Each‘ which basically works like forEach and ‘Do Until‘ which is basically the traditional do-while.
And with that a requirement come often. How do I get the iteration index or index number in these loops. We will cover first for ‘Do until‘ and then the ‘Apply to each‘.
Whenever we come to requirement like this, we usually talk about using a variable and then incrementing it. However if you are using ‘Do until’, you don’t need to do anything like that. This is because there is OOB function in Power Automate to do so.
And that function is iterationIndexes. Below is Power Automate flow with iterationIndexes in action.
As you can see from the above screenshot, I am using Do-until with till fourth iteration only. Below is the formula
iterationIndexes('Do_until')
Remember ‘Do_until’ in the above formula is basically the name of the ‘Do until’ action step. If you have renamed your step you should change the formula accordingly.
Now comes Apply to each. Unfortunately iterationIndexes won’t work with them. We have to fallback to the usual way of using a custom variable and increment.
I am not going to explain it again and reinvent the wheel. Quite nicely explained here.
Hope this helped!
Debajit Dutta
Business Solutions MVP
Discover more from Debajit's Power Apps & Dynamics 365 Blog
Subscribe to get the latest posts sent to your email.