web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Count Items in a List ...
Power Automate
Suggested Answer

Count Items in a List based on Date

(1) ShareShare
ReportReport
Posted on by 20
I am trying to build a flow that updates an item in a Sharepoint list with a custom number formatted like YY-0000. I want the flow to count how many items are in the list with a 'Date Received' column value of the current year, then add 1 to that sum and use it to update the item with my custom number. 
 
These are my current actions (initialize variable uses length to count the output of get items, then tasker value is a compose that adds 1 to the variable). 
 
I am struggling with how to filter the Get Items to pull only items in the list where Date Received is in the current year. Any advise on how to format the query to avoid getting errors? Is there a better way to do a conditional count in Power Automate?
Categories:
I have the same question (0)
  • Suggested answer
    Michael E. Gernaey Profile Picture
    53,392 Super User 2025 Season 2 on at
    Hi,
     
    First thank you for such clear details and a flow picture, I love you for that, no sarcasm intended.
     
    However, I must warn you, that asking a Flow to generate you a sequenced number will fail at some point. Multiple people will hit at the same time,
    and the flow will get the count and then both will end up with the same number, it's going to happen, especially as your customers/users whatever grows.
     
    If anything, assuming I am clear what you need, you can set the Triggers (under settings), Concurrency ON and set to 1. Then its only 1 at a time.
    Then it should be fine, unless you have loads of volume of uses and then they will be grrrr'd lol to have to wait.
     
    So, is your Column a Date or a DateTime as that makes a big difference?
     
    So what we need to do is make sure that we have a formatted Date that matches what yours is.
     
    So for instance.
     
    If you have dd-MM-yyyy in the List, then we need to match that. To do that, use the following expression
     
    Expression: formatDateTime(utcNow(), 'dd-MM-yyyy')
     
    Then in your get items 
    [Date Received] eq ' formatDateTime(utcNow(), 'dd-MM-yyyy')'
     
    Please let me know if you have any issues.
     
     
  • Suggested answer
    vgolla Profile Picture
    2 on at
    add a Select action next to get items

    Then add “filter array” action to filter items that are in current financial year.
     
    then use a Compose action to count the length of array.
  • abc 123 Profile Picture
    784 Moderator on at
    In a multi-user environment, you'd need a separate list to hold the "Next value", along with a locking Semaphore such that only one user at a time could access and increment the value.  It's a total PITA, and still susceptible to duplication, so WHY is this required? Who's asking for it, and what other methods can be used to make a unique identifier. For example, can the YY-ItemID suffice?
     
    As developer, we sometimes have to push back against requirements to prevent excessive development time and risky situations.
  • KG-13081359-0 Profile Picture
    20 on at
    @FLMike
     
    I think it is unlikely there will be too many issues with people trying to add items at exactly the same time based on number of users/the material being added to the list, but I did go ahead and set the concurrency to 1 like you suggested just to be safe.
     
    My Date Received column is in date format so I set my filter to:
    Date Received eq 'formatDateTime(utcNow(), 'yyyy-dd-mm')'
     
    However, that is giving me an error. 
     
    I am trying to filter just based on the year in the date received column, so right now it will count all the items (since they were all entered at some point in 2024), but when 2025 begins it will only count items where the date received is in 2025. 
     
    I had previously tried formatting the query as:
    formatDateTime(triggerOutputs()?['body/DateReceived'], 'yyyy') eq 'formatDateTime(utcNow(), 'yyyy')
     
    but that returned this error:

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 501 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 323 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard