How to Count Items in an Array in Power Automate

Do you need to count the number of items in your array in Power Automate?

You might need to know how many rows your data source has returned in your flow. Your action will return an array of records with your data, so counting these will let you know how many rows have been returned from your action.

This post will show you how to use the length function to count the items in your array.

Count Items in an Array with the Length Function

[
{"name": "John"},
{"name": "Fred"},
{"name": "Mark"}
]

This example shows an array with three items created with a compose action. How can you count the items in this array?

@{length(outputs('Compose'))}

The above length formula will count the number of items in the array from the Compose action.

  1. Click on the field where you want to return the count of the array items. In this example, the count will be returned in a Compose action.

This should show the expression editor where you can add the formula to count the items.

  1. Click on the Expression tab.
  2. Enter the length() part of the formula.
  1. Click on the Dynamic Content tab.
  2. Now choose the dynamic content of the array to count. This will add the references to your expression formula.
  3. Click on the Ok button to add the formula to your flow.

This should create the formula block in your flow which will evaluate to the count of the number of items in the array!

Conclusions

That’s it! It’s an easy solution since there is a function specifically for counting the items in an array.

Hopefully, this helped you out. Let me know in the comments!

About the Author

John MacDougall

John MacDougall

John is a Microsoft MVP and freelance consultant and trainer specializing in Excel, Power BI, Power Automate, Power Apps and SharePoint. You can find other interesting articles from John on his blog or YouTube channel.

Related Articles

Comments

0 Comments

Get the Latest Tech Tips

Write For Us

Are you a tech enthusiast with a talent for writing great content? Come write for us!

Follow Us

Follow us on social media to stay up to date with the latest in tech!