Showing results for 
Search instead for 
Did you mean: 

Better and more robust looping functions

From what I can tell, practically anything that performs looping functionality (mainly ForAll) wants to return a table. This means that the actions that are performed inside of the loop need to be returning values that it can then build its table with.


My current situation, and one that I believe is probably pretty common, requires me to loop through a collection and perform actions for each iteration without returning any values. Unfortunately, the obvious choice to use ForAll doesn't work since the first action I need to do is set a temporary variable (using either Set or UpdateContext) which it doesn't accept.


What I propose is that some proper/basic looping functionality is added that doesn't require any return values and has no bias on the type of actions performed inside. We need some options that don't require a hacky combination of 3+ functions that simply allow us to iterate over data. Loops such as For, ForEach(x in x_collect), Do-While, etc.

Status: Under Review

Updating status and adding @GregLi

Not applicable

Addition of loop is a good idea.


When Microsoft is going to add this feature.

Power Apps
Status changed to: Under Review

Updating status and adding @GregLi

Helper II

This is a much needed feature.

Without the ability to loop through a data set (collection, list box, data connection, etc...) Powerapps is severly limited.  Anyone with development experience uses looping techniques.


We need to update records in a database or collection based on a collection of selected items.  ForAll does not work for this.  We need While, ForEach, etc...

Thank you


Frequent Visitor

Currently trying to figure out how to run a set of commands based on a gallery item value. I'm looking for something similar to "for(UpdateContext({i:0}); i < Gallery1.Selected.iteratorValue; UpdateContext({i:i+1})) { //run commands}

found a solution using the Timer control, not very clean and very restricted, but then ran into a roadblock with needing to run the same code block but for all items in the gallery, essentially needing a nested for loop. 


This is for an application that will allow you to auto schedule a ticket by running a Collect command into a collection based on the value of the Estimated Hours of the selected gallery item. (Ex: Estimated Hours = 5, run the Collect command 5 times to record it in another Work Schedule collection).


Because of the current limitation, i'm having to drop this feature, which is a shame.  

There's a real need to iterate a set of commands based on an arbitrary value that is dynamically set. 

Please consider implementing this as soon as possible. 


Thank You




It's possible to set up a loop through a Topic, which I believe this comment is about.  It's not intuitive, though, but here's how you can do it:


-Create a topic where you want to put the user in a loop until a condition is met (we use it for validating a user alias or making sure a new project name is available, but whatever.

-Ask the question you want to have in a loop

-Create your conditional and the response; there will be one response that will trigger the loop (not found, etc. - we'll call this the "negative" loop)

-For the negative loop, select Question

-Drag the connecting line back to the original question to create the loop (and then delete the orphaned question you just created)


That's it.  Respond back to me if you're stuck and want a screenshot.