In this Power Automate tutorial, we will see how to count items in an array using Power Automate. Also, we will see how to count unique items in an array with length() function in Power Automate.
Here we are going to cover the below topics.
- How to count items in SharePoint in Power automate
- How to count items in array variable in Power automate
- How to count SharePoint list items in the filter array in Power automate
- How to count items in json array variable in Power automate
- How to count distinct items in array variable in Power automate
How to count items in a SharePoint list in Power automate
Here we will see how to count items in a SharePoint list using Power Automate.
For example, I have a Product details list in SharePoint, so we will get all the items from the SharePoint list. Then using the length() method we will count the items.
The SharePoint list contains the below columns:
- Title -Single line of text
- Name- Single line of text
- Description-Multiple lines of text
- Price- Currency
- Quantity-Number
Step 1: Log in to Power Automate and click on the +Create icon -> select Instant Cloud flow.
Then provide the flow name and select the Manually trigger a flow. Then click on Create.
Now you can see Manually trigger a flow action is added to the flow.
Step 2: To get items from the SharePoint list, so, click on the +New step -> Select Get items action. Then provide the below information:
- Site address: Provide the SharePoint site address
- List name: Select the list from the dropdown.
Step 3: Now we will count the items using length (), so click on the +New step -> select compose action. Then provide the below information:
- Inputs: provide the below expression
length(outputs('Get_items')?['body/value'])
Step 4: Now save the flow and run the flow manually. For this, click on the test button -> select manually and click on Test. You can see the flow run successfully.
This is an example of counting items in a SharePoint list using Microsoft Power automate.
How to count items in array variable in Power automate
Here we will see how to count items in the SharePoint list using Power Automate.
For example, we will count the items in an array [“apple”, “banana”, “orange”, “grape”] using the length method. In this, we will count the item there are 4 items so it will return 4.
Step 1: Log in to Power Automate and click the +Create icon -> select Instant Cloud flow.
Then provide the flow name and select the Manually trigger a flow. Then click on Create.
Now you can see Manually trigger a flow action is added to the flow.
Step 2: Next we will initialize an array variable containing an array of names, so click on the +new step -> select Initialize variable action. Then provide the below information:
- Name: Provide the variable name
- type Select type as array.
- Value: Provide the value like below
["Alex", "Baron", "John", "Rosy"]
Step 3: Now we will count the item in an array, so, click on the +New step -> select Compose action then provide the below expression:
length(variables('Names'))
Step 4: Now save the flow and run the flow manually. For this, click on the test button -> select manually and click on Test. You can see the flow run successfully.
This is an example of counting items in an array variable in Power Automate.
How to count SharePoint list items in a filter array in Power automate
Here we will see how to count SharePoint list items after filtering an array in Power Automate.
For example, I have a Product details list in SharePoint, so we will get all the items from the SharePoint list. Then we will filter the array based on the quantity of products, after that, we will use the length() method we will count the items.
The SharePoint list contains the below columns:
- Title -Single line of text
- Name- Single line of text
- Description-Multiple lines of text
- Price- Currency
- Quantity-Number
Step 1: Log in to Power Automate and click the +Create icon -> select Instant Cloud flow.
Then provide the flow name and select the Manually trigger a flow. Then click on Create.
Now you can see Manually trigger a flow action is added to the flow.
Step 2: To get items from the SharePoint list, so, click on the +New step -> Select Get items action. Then provide the below information:
- Site address: Provide the SharePoint site address
- List name: Select the list from the dropdown.
Step 3: Now we will filter the array of items, based on quantity is greater than 50, so, click on the +New step -> select Filter array action. Then provide the below information
- From: Select the value from dynamic content.
- Choose a value: Select the quantity from dynamic content.
- Operator: Select the operator as ‘is greater than’.
- Choose a value: Write 50
Step 4: Next we will check the length of the filtered array, so, click on the +New step -> select Compose action. Then provide the below information:
- Inputs: Provide the below expression:
length(body('Filter_array'))
Step 5: Now save the flow and run the flow manually. For this, click on the test button -> select manually and click on Test. You can see the flow run successfully.
This is an example of counting SharePoint list items in a filter array using Power Automate.
How to count items in json array variable in Power automate
Here we will see how to count items in a SharePoint list using Power Automate.
For example, we have an array of objects, to count the number of objects we will use the length().
Step 1: Log in to Power Automate and click the +Create icon -> select Instant Cloud flow.
Then provide the flow name and select the Manually trigger a flow. Then click on Create.
Now you can see Manually trigger a flow action is added to the flow.
Step 2: Next we will initialize an array variable containing the array of names, so click on the +new step -> select Initialize variable action. Then provide the below information:
- Name: Provide the variable name
- type Select type as array.
- Value: Provide the value like below
[
{"name": "Alice", "age": 30},
{"name": "Bob", "age": 25},
{"name": "Charlie", "age": 40}
]
Step 3: Now we will count the item in array, so, click on the +New step -> select Compose action then provide the below expression:
length(variables('Names'))
Step 4: Now save the flow and run the flow manually. For this, click on the test button -> select manually and click on Test. You can see flow run successfully.
This is an example of counting items in json array variable using Power Automate.
How to count distinct items in array variable in Power automate
Here we will see how to count distinct items in an array variable in Power Automate.
For example, we have an array [ 1,2,3,4,5,3,4], then we will apply intersection() to get the distinct or unique items and then count distinct items in Array.
Step 1: Log in to Power Automate and click the +Create icon -> select Instant Cloud flow.
Then provide the flow name and select the Manually trigger a flow. Then click on Create.
Now you can see Manually trigger a flow action is added to the flow.
Step 2: Next we will initialize an array variable containing an array of names, so click on the +new step -> select Initialize variable action. Then provide the below information:
- Name: Provide the variable name
- type Select type as array.
- Value: Provide the value like below
[
{"name": "Alice", "age": 30},
{"name": "Bob", "age": 25},
{"name": "Charlie", "age": 30},
{"name": "David", "age": 22},
{"name": "Eve", "age": 25}
]
Step 3: Next we will add Select action that will only select the age column, so click on the +New step -> select ‘Select’ action. Then provide the below information:
- From: Select the array variable from dynamic content.
- Map Key: Write the key as Age
- Map Value: Provide the below expression:
item()?['age']
Step 4: Now we will find the distinct items from the array and then count the items. So, click on the +New step -> select Compose action. Then provide the below information:
- Inputs: Provide the below expressions:
length(intersection(body('Select'),body('Select')))
Step 5: Now save the flow and run the flow manually. For this, click on the test button -> select manually and click on Test. You can see the flow run successfully.
This is an example of counting unique items in an array in Power Automate.
Conclusion
In this Power Automate tutorial, we saw how to count items in an array using Power Automate flow. Here is the example we have covered:
- Power automate count items in the SharePoint list
- Power automate count items in an array variable
- Power automate count items in the filter array
- Power automate count items in a json array variable
- Power automate count distinct items in an array variable
You may also like:
- Convert an array to a string using Power Automate
- Convert XML to Array in Power Automate
- How to create an array from an Excel table using Power Automate?
- Create an HTML Table from an Array in Power Automate
I am Bijay a Microsoft MVP (10 times – My MVP Profile) in SharePoint and have more than 17 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com