A common requirement in lists, both in Sharepoint and the new MS Lists, is to create dynamically-updating time counters that keep ticking over without you having to refresh or change the List manually. For instance, I have a Flow that triggers when a certain Sharepoint List item has exceeded two days in age and a few other criteria. While you can create time delays and the like in your Flow, you may wish to reflect the time passed directly in the List. This article describes an easy way to achieve this in Power Automate. Note that this is a specific application of incrementing a variable.
Example
Say that you have a Sharepoint List item in which you wish to populate a dynamically-updating 'hours elapsed' column so that a) this can be used in other calculated columns, which must change value when a certain amount of time has passed, and b) anyone viewing the item can see the hours elapsed without having to refresh the item.
The Broad Approach
One rookie error would be to try and use a formula in the list, for example a DATEIF formula or calculating the difference between a TODAY function and the creation date of the item. Unfortunately, these do not update dynamically, i.e. they will only re-calculate when the item is modified. This would not work for the above scenario. Instead, I achieve the dynamically-updating counter by using a Do Until loop in Power Automate with a incremented integer variable, a Update Item action, and a delay:
The following sections explain each step.
Step 1: Initialize the Integer Variable
First, initialize an integer variable starting at -1 (this is assuming you want your time to increment by 1, obviously you can alter this). The reason for the -1 is that once you run the flow element (which is effectively at time zero), the Do Until will immediately increment to zero.
Step 2: Create the Do Until Loop with Appropriate Settings
Create the Do Until action:
Here, I am wanting the hour counter in the list to increment hourly, and I want it to do so for 29 days (because this is part of an approval flow, and approvals timeout in 30 days, I have chosen to terminate the flow after 29 days without a response to avoid flow failure). Therefore, I first set the Do Until to stop when the counter reaches 695, as 695 hours are just under 29 days. Under limits, I therefore also put 695 as the count (number of times to loop), and the timeout to be 29 days (P29D).
Step 3: In the Do Until, Increment the Variable
Within the Do Until loop, increment the variable (in this case, by 1).
Step 4: Still In The Do Until Loop, Update the List Item with the New Incremented Variable Value
Update your List item with the latest variable value.
Step 5: Still In The Do Until Loop, Delay the Loop
Finally, use a delay action to delay the loop, in this case I delay by an hour so that the counter increments once per hour:
As noted, the Sharepoint list will automatically update every hour, reflecting the number of hours elapsed. This can obviously be used to reflect other time increments too.