How To Use The Power Automate Do Until Loop

Power Automate Do Until Loop

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.

  1. Create a new instant cloud flow

    Power Automate Create Instant Cloud Flow

    Instant cloud flow

  2. Give your flow a name and select type ‘Manually trigger a flow’

    Power Automate Do Until Example Flow

    Setup your flow

  3. Add a ‘Initialize variable’ action

    Power Automate Initialize Variable Counter

    Initialize variable Counter

  4. Add a ‘Do until’ step and setup your condition

    Power Automate Do Until Loop

    Do until action

  5. Add a ‘Increment variable’ action

    Power Automate Increment Variable Counter

    Increment variable Counter

  6. Do a test run and check when the do until loop stops

    Power Automate Run Do Until Flow

    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.

Count

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
Power Automate Do Until Count
Do Until Count option

Timeout

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.

FormatMeaning
P5D5 days
PT2H2 hours
PT15M15 minutes
P1DT6H30m1 day, 6 hours and 15 minutes
ISO 8601 duration examples

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.

Power Automate Do Until Advanced Mode
Do until advanced mode

Within advanced mode you can formulate complex expressions with ‘or’ and ‘and’.

The following example has two conditions.

Power Automate Do until multipile conditions advamced mode
Do until with two conditions

The expression checks if the variable is greater 20 and less than 30. It evaluates to true for 21, 22, ..,29.

@And(greater(variables('Counter'), 20),less(variables('Counter'),30))

Do until index

You can reference the index of the current iteration like this:

Power Automate Do Until Index
Do until current iteration index

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:

Power Automate Do Until Delays
Do until with delay

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.

Leave a Comment

Your email address will not be published.