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 total of items p...
Power Automate
Unanswered

Count total of items per country in one list then update total to another column in another list

(1) ShareShare
ReportReport
Posted on by Microsoft Employee

I am trying to create a flow that will count the total of items per site/country in List A then populate in List B the total returned in another column for that specific site/country.  Example: count total of staff against London in List A then populate in List B the total. And i need the flow to run every time there is a change to the number of staff in List A for that particular location.

 

Please help!

Categories:
I have the same question (0)
  • vayinapurapu1 Profile Picture
    233 on at

    Can you try the following steps?

    1) Create a flow with trigger on item created or modified

    2) Use SharePoint Get Items from List A and store the count in variable

    3) Update the value of count in list B using update item action

    Couple of points to consider, Make sure the flow is not running under infinite loop, use proper condition to trigger

    https://www.youtube.com/watch?v=oKN4_5o2NUA&t=40s

    Also Get items by default gets top 100 records. If the items are less than 5000 you can either use pagination. Below is the video that gives more insights

    https://www.youtube.com/watch?v=X-urscD106Y

    hope this helps.

     

    Cheers,

    Vinay.  

  • LearnDayByDay Profile Picture
    Microsoft Employee on at

    Hi Vinay

    Screenshot 2022-08-22 155923.png

    thanks for the help here. On Step 2- store the count in variable: can you explain a bit more? And on Step 3 i assume i will use the variable dynamic content in the column i need the total updated in...

     

    attached screenshot is how far i have got.

  • LearnDayByDay Profile Picture
    Microsoft Employee on at

    Hi Vinay, have you had any thoughts on this?

  • vayinapurapu1 Profile Picture
    233 on at

    Update the request count

    Introduction: In this article, we will go through how to update the list column based on requests on other lists. Here I have 2 lists one is requests and other is countries.

    In the requests list ‘Country’ is a look up column.

    vayinapurapu1_0-1661924852921.png

     

    vayinapurapu1_1-1661924852928.png

     

    Here the property ‘RequestCount’ contains the count of requests based on ‘Requests’ list.

    Flow Design:

    Now we will go through the steps of designing the flow.

    Step 1:

    Login to Power Automate portal (https://make.powerautomate.com) with your organization account.

    Step 2:

    Select the trigger point as SharePoint and select ‘On item created or modified’.

    vayinapurapu1_2-1661924852939.png

     

    Step 3: Get items from the countries list.

    vayinapurapu1_3-1661924852953.png

     

    Step 4: From the countries list we need ID and the Country names. These are needed to update the list item properties. Here create the JSON object using the ‘Select’ data operation.

    vayinapurapu1_4-1661924852982.png

     

    • From: property is dynamic property ‘value’ from the ‘Get items – Countries’ action.
    • Map:
      • Here since we need JSON object enter the first key as ID, and values as item()?[‘ID’]
      • Enter the other key as ‘Country’ and the value is item()?[‘Title’]

     

    Step 5: create ‘Apply to Each’ and inside add ‘compose’ action and log the current item. At first we will get the country value from the current json object.

    vayinapurapu1_5-1661924852985.png

     

    Step 6: Now add ‘Get Items’ and configure the action to get the requests that satisfies the filter query where the current item country equals the country property of the requests.

    vayinapurapu1_6-1661924853003.png

     

    In the filter query I have updated the property as Country/Title, since country is look up column and it requires specific format to check the filter. More about the OData can be found in references section.

    And the value is the dynamic outputs of compose action log current item.

    Step 7: Now here I am getting the length of collection and checking if the count greater than or equal to 1.

    vayinapurapu1_7-1661924853009.png

     

    length(outputs('Get_items-Requests')?['body/value'])

     

    Step 8: If the collection has value and go ahead update item with Request count.

    vayinapurapu1_8-1661924853018.png

     

    • For update item we need ID, Title properties
    • For ID: this is expression where you need to select ID from the current item of apply to each loop.

                   

    vayinapurapu1_9-1661924853022.png

     

    • Same thing applies for country.

               

    vayinapurapu1_16-1661925216102.png

     

     

     

    • Request Count: Update the with expression length of collection from Get items action.

       

    vayinapurapu1_17-1661925242187.png

     

     

     

    vayinapurapu1_12-1661924853056.png

     

    Step 9: Below is the complete flow and it should similar to below.

    vayinapurapu1_13-1661924853063.png

     

    please note that you may have to avoid infinite loops if you are using trigger on item created or modified. Refer to the article in references. 

    References:

    https://www.youtube.com/watch?v=yeAnuTB85eg

     

    Stopping Infinite Loops When Updating SharePoint List Items – Scott J Shearer – M365 and Power Platform Solutions (o365scott.blog)

     

  • vayinapurapu1 Profile Picture
    233 on at

    @LearnDayByDay does this meet your needs? Please let me know.

  • LearnDayByDay Profile Picture
    Microsoft Employee on at

    Hi, i am going to try this solution today. I will update you with my results 🙂 thank you so much!

  • LearnDayByDay Profile Picture
    Microsoft Employee on at

    im stuck on Step 5. see screenshot..i cannot get the inputs you show on your example from previous step. What goes in the Apply to Each Output?

    LearnDayByDay_0-1662666828162.png

     

  • vayinapurapu1 Profile Picture
    233 on at

    Can you try the below post. I have also updated the flow in this post

    Updating List Properties Using Flow (c-sharpcorner.com)

    Hope this helps. 

  • LearnDayByDay Profile Picture
    Microsoft Employee on at

    Hi Vayina

     

    i have tried following your steps a couple of times using my current Lists and creating lists from new and i cannot replicate what you have shown here. The Step By Step you have provided does not mirror the Step 9 of what the finished flow should look like.

    I am unable to get the Input of Country as shown in Step 5, also on Step 8 the ID and Title field does not give me the 'ID' and 'Country' expression to pick from under the dynamic content.

     

    Happy to organise a Teams meeting to go over it if you are willing?

  • vayinapurapu1 Profile Picture
    233 on at

    did you try adding 'Apply to each' action at step 5? Then add the compose action as shown in the steps. 

    vayinapurapu1_1-1663650869151.png

     

    for the section 'Select an ouput from previous stage' please select the dynamic output from the select Country Names compose action. Please let me know how it goes or for any further questions. 

     

    Thanks,

     

    Vinay. 

     

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 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard