cancel
Showing results for 
Search instead for 
Did you mean: 

Create a dynamically-updating time counter in a list using Power Automate

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:

 

Picture1.png

 

The following sections explain each step.

 

Step 1: Initialize the Integer Variable

Picture2.png

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:

Picture3.png

 

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).

Picture4.png

 

Step 4: Still In The Do Until Loop, Update the List Item with the New Incremented Variable Value

Picture5.png

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:

Picture6.png 

 

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.  

Meet Our Blog Authors
  • Experienced Consultant with a demonstrated history of working in the information technology and services industry. Skilled in Office 365, Azure, SharePoint Online, PowerShell, Nintex, K2, SharePoint Designer workflow automation, PowerApps, Microsoft Flow, PowerShell, Active Directory, Operating Systems, Networking, and JavaScript. Strong consulting professional with a Bachelor of Engineering (B.E.) focused in Information Technology from Mumbai University.
  • Encodian Owner / Founder - Ex Microsoft Consulting Services - Architect / Developer - 20 years in SharePoint - PowerPlatform Fan
  • Cambridge UK Power Platform User Group Leader, Technical evangelist and speaker. Always says yes to coffee! #LetsGetCoffee
  • Passionate #Programmer #SharePoint #SPFx #Office365 #MSFlow | C-sharpCorner MVP | SharePoint StackOverflow, Github, PnP contributor
  • I am building business processes and applications that are easy for users' to stick to, so they can follow and understand them. In overall I transform processes to be more reliable and effortless. I am a proud co-organizer of SharePoint Saturday Warsaw and active community member, blogger and international speaker.