Skip to main content

Notifications

Community site session details

Community site session details

Session Id : AbE9JoDHYX5hN0/gpfvgYu
Power Automate - Building Flows
Answered

Count items in a for each

Like (0) ShareShare
ReportReport
Posted on 28 Aug 2023 23:52:06 by 12

Hi all,

 

Im have an Azure Devops query that displays all the "In Progress Items" for different teams. The results of the query looks like this: (results is about 300 lines)

 

Title      |     State       | Area Path

Item1         Active       Companyname\Area\Team1

Item2         Active       Companyname\Area\Team2

.... and so on..

 

I made a flow that:

1. Read the query results

2. For each item it extracts the team name from the Area Path field ... example "Team1" or "Team2".  

 

What i need help with, is to count each of the items PER team daily and save each on row on a Sharepoint. So the sharepoint list looks like this:

Team      |        Date        |      Count

Team1       Date of run            65

Team2       Date of run            80

....

 

The reason for this is that i want to calculate the Work In Progress Items per day per team (historic) so i can use it on a PowerBi report. Can anyone help me?  Let me know if more information is needed

 

Thanks

JTS

  • jsanjurr Profile Picture
    12 on 30 Aug 2023 at 01:09:51
    Re: Count items in a for each

    @creativeopinion  Thank you very much. Youve teach me a lot and helped me immensely.  Its working perfect now. 

  • Verified answer
    creativeopinion Profile Picture
    10,406 Super User 2025 Season 1 on 30 Aug 2023 at 00:39:46
    Re: Count items in a for each

    @jsanjurr Sorry about that I misread your original post and requirements regarding that.

     

    In the length() expression you need to insert the Body outputs from the Filter Array action. This will return the number of items returned from your Filter Array action.

  • jsanjurr Profile Picture
    12 on 30 Aug 2023 at 00:23:26
    Re: Count items in a for each

    @creativeopinion the reason i dont have the SP ID is cause i wont be updating i will be creating a new entry each time. 

     

    I had contain but i recreated the flow and i missed. I have included it again

     

    What should i put inside the length()?  I missing that

  • creativeopinion Profile Picture
    10,406 Super User 2025 Season 1 on 29 Aug 2023 at 23:27:40
    Re: Count items in a for each

    @jsanjurr 

    In the Select action where you get the Team Name, you are missing the SP ID. Without the ID, you won't be able to update the SP item. Please refer to the screenshot in my original post with the instructions under the Get Team Names heading.

     

    Your Filter Array action operator should be contains, not is equal to. 

  • jsanjurr Profile Picture
    12 on 29 Aug 2023 at 23:03:07
    Re: Count items in a for each

    @creativeopinion for some reason all my replies today were deleted so ima try one more time.  

    Thanks for the help btw. But i have some questions

    1. What should i get inside length()?

    2. When i run a test i see that the Body of the Filter Array is empty, im attaching my image so u can take a look if i have something wrong

    img1.png

    img2.png

  • creativeopinion Profile Picture
    10,406 Super User 2025 Season 1 on 29 Aug 2023 at 02:33:52
    Re: Count items in a for each

    @jsanjurr That's not an issue. I've updated the original post with the instructions. You need to get the list of Teams and use an apply to each action. See my original post. Hope this helps.

  • jsanjurr Profile Picture
    12 on 29 Aug 2023 at 00:08:38
    Re: Count items in a for each

    @creativeopinion thanks for the reply, but i forgot to mention. I have around 50+ teams so doing it and maintaining it will be a nightmare

  • creativeopinion Profile Picture
    10,406 Super User 2025 Season 1 on 29 Aug 2023 at 00:05:23
    Re: Count items in a for each

    @jsanjurr 

    You need a Select and Filter Array action to get your count of items. 

    Select Action – Devops Query

    Add a Select action to your flow and insert the outputs from the Azure Devops query. For my example I'm using a SharePoint list. The concept is the same.

     

    Click the icon, to change from Map to text mode.

    creativeopinion_0-1693267320843.png

     

    Get Team Names

    Add a Get Items action to return the items from your Team list. Select action to grab the Team name from your list and an Apply to Each action to loop through each team.

     

    For this select action, you will need to use the Map mode. You will need the SP Item ID to update the item.

    creativeopinion_1-1693275483376.png

     

    Apply to Each – Team Name

    Add an Apply to Each action. This action will loop through each Team name returned. Insert the outputs from the Select action that contains the array of Team Names and their respective SP ID. 

     

    I've added a Compose action as well to store the Team name as you'll need it in the next action. 

     

    I used an expression:

    item()?['Team Name']

    If your Select action key is different, you'll need to replace Team Name with your key text.

    creativeopinion_5-1693276054293.png

     

    Filter Array

    Add the Filter Array action into the Apply to Each action. In the From field, insert the outputs from the Select action that you used on the Azure Devops outputs.

     

    In the first value field, insert an expression to access the content.

    item()

     

    Change the operator to contains.

     

    In the second value field, insert an expression (or in my case— I've inserted the outputs from above that contain the Team name.

    creativeopinion_3-1693275723678.png

     

    Add a Compose action below the Filter Array action and use the length() function to return the count from the Filter Array action. Insert the Body outputs from the Filter Array action. 

    creativeopinion_6-1693276154481.png

     

    Condition – Check Count

    Add a Condition action to check the count of the items returned. If the count is greater than zero, add the Update Item or Create Item action into the Yes branch.

     

    This way, the Update Item action will only run if there are items returned from the Filter Array action.

     

     

    creativeopinion_4-1693275926874.png

    Update Item

    Ensure you are using the content from the Filter Array action in your Update Item action. You will need to use an expression to access this content. This YT Short covers how to do that.

    creativeopinion_8-1693276309391.png

     

     

    Hope this helps!


    If I helped you solve your problem—please mark my post as a solution ✅.
    Consider giving me a 👍 if you liked my response!

    👉Watch my tutorials on YouTube
    👉Tips and Tricks on TikTok

     

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Automate - Building Flows

#1
stampcoin Profile Picture

stampcoin 61

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 47 Super User 2025 Season 1

#3
rzaneti Profile Picture

rzaneti 31 Super User 2025 Season 1

Overall leaderboard