Do Until within Power Automate can be a powerful tool if you understand how it works. This guide explains the Do until loop by starting with the most simple example use case for Do until. Afterwards more advanced aspects are explained.
Step by step: Simple Power Automate Do Until example
Follow this guide to understand the Do Until loop in Power Automate. In the example a counter starting at 1 is incremented in each duration. The Do until condition says to stop the loop as soon as the Counter is greater than 3. The last value well be a 4 because the condition is checked at the end of every iteration.
Create a new instant cloud flow
Instant cloud flow
Give your flow a name and select type ‘Manually trigger a flow’
Setup your flow
Add a ‘Initialize variable’ action
Initialize variable Counter
Add a ‘Do until’ step and setup your condition
Do until action
Add a ‘Increment variable’ action
Increment variable Counter
Do a test run and check when the do until loop stops
Counter has value 4, because 4 is greater than 3
Power Automate Do until limits
When the condition of your Do until is never met, there might be an endless loop. This why there Power Automate Do until limits to stop the execution even if your condition is not met.
What does the ‘Count’ setting under ‘Change limits’ do? It simply limits the max number of iterations of the loop. It may end earlier, in case the condition of the D until is reached before.
When we set ‘Count’ to two in the setup described above. The final value of ‘Counter’ would be 3 and not 4.
- Iteration #1: Counter value 1 is incremented by 1 = 2
- Iteration #2: Counter value 2 is incremented by 1 = 3
- Do until stops, because the Count of 2 iterations is reached
The timeout setting limits the maximal time that the Do Until loop waits to fulfill the given condition. In case the timeout is set to 5 minutes, the Do Until loop will simply stop the loop. In case the condition is met before the timeout is reached, it stops earlier.
The Power Automate Do Until timeout settings might have a strange syntax at first sight.
The default value is set to PT1H, which means one hour. The upfront P stands for period. T stands for time. H stands for hour.
For a detailed explanation of the format, go to the Wikipedia site on ISO 8601.
Note: The maximum duration allowed is P30D (30 days).
Examples Do until timeout format
Here are some examples of the do until timeout format you can modify to your needs.
|P1DT6H30m||1 day, 6 hours and 15 minutes|
Multiple conditions with advanced mode
Sometimes one condition is not enough. For instance, you want to check if a value is between two dates.
In case you want to use Do Until with multiple conditions you need to use the advanced mode.
Within advanced mode you can formulate complex expressions with ‘or’ and ‘and’.
The following example has two conditions.
The expression checks if the variable is greater 20 and less than 30. It evaluates to true for 21, 22, ..,29.
Do until index
You can reference the index of the current iteration like this:
Note: The index starts at 0 and not on 1.
Do until with delay
You can use delay within a do until loop like this for example:
Please be aware that the maximum duration of a flow is 30 days and also make sure that your timeout under ‘Change limits’ fits your requirements.
FAQ – Power Automate Do until
Is there a way to break a Do until loop in Power Automate?
No, there is no dedicated break function for Do until loop. In some cases the Terminate action might help. Be aware that Terminate exits the execution of the whole flow.