Skip to main content

Notifications

Tip #1431: Power Automate loops without variables

Community Member Profile Picture Community Member Microsoft Employee

When makers need a loop with a counter in Power Automate, say from 1 to 20 (or 0 to 19 for all of you developers out there), the immediate reaction I’ve observed is to reach for a gun variable:

You don’t have to because there are at least two methods that avoid those variables and associated extra actions (that you pay for!).

Method 1: createArray

Use createArray function as the input for the Apply to each loop. This method works for small number of iterations (upper limit is how many comma-separated numbers you can type without getting carpal tunnel syndrome). Big advantage is ability to use custom values for iterations. For example, if you want to loop over the number of days in all months, you can use createArray(31,28,31,30,31,30,31,31,30,31,30,31). Using other data types is also possible, e.g. createArray('One', 'Two', 'Three') or createArray('', '', '️'). Get the current index value as item() or items('Loop_name') (latter works for nested loops as well).

Method 2: endless loop with the limit

Expand Change limits and set the Count to whatever is needed. Brevity is the winner here. The downside is pro-style zero-based indexing. Get the current index value as iterationIndexes('Loop_name') (yes, it’s now documented).

Comments

*This post is locked for comments