How to count items in an array using Power Automate?

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
count items in a SharePoint list in Power automate

Step 1: Log in to Power Automate and click on the +Create icon -> select Instant Cloud flow.

power automate count items in SharePoint list

Then provide the flow name and select the Manually trigger a flow. Then click on Create.

power automate count items in SharePoint list

Now you can see Manually trigger a flow action is added to the flow.

Microsoft power automate count items in array

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.
Microsoft power automate count items in SharePoint list

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'])
power automate count items in SharePoint list

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.

Microsoft power automate count items in SharePoint list

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.

power automate count items in array variable

Then provide the flow name and select the Manually trigger a flow. Then click on Create.

power automate count items in array

Now you can see Manually trigger a flow action is added to the flow.

Microsoft power automate count items in array

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"]
Microsoft flow count items in array variable

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'))
Microsoft power automate count items in array variable

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.

How to count items in array variable in Power automate

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
Using Microsoft power automate count items in filter array variable

Step 1: Log in to Power Automate and click the +Create icon -> select Instant Cloud flow.

power automate  count SharePoint list items items in filter array

Then provide the flow name and select the Manually trigger a flow. Then click on Create.

power automate count SharePoint list items in filter array

Now you can see Manually trigger a flow action is added to the flow.

Microsoft power automate count items in array

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.
Microsoft power automate count items in filter array variable

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
power automate count items in filter array variable

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'))
power automate count items in 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.

Using Power automate count items in filter array

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.

power automate count items in json array variable

Then provide the flow name and select the Manually trigger a flow. Then click on Create.

power automate count items in json array

Now you can see Manually trigger a flow action is added to the flow.

Microsoft power automate count items in array

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}
]
Microsoftpower automate count items in json array variable

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'))
power automate count items in json array variable

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.

Microsoft power automate count items in json array variable

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.

power automate count unique items in array variable

Then provide the flow name and select the Manually trigger a flow. Then click on Create.

power automate count distinct items in array

Now you can see Manually trigger a flow action is added to the flow.

Microsoft power automate count distinct items in array

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}
]
Microsoft power automate count distinct items in array variable

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']
power automate count distinct items in array variable

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')))
Microsoft power automate count unique items in 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.

power automate count unique items in array

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:

>