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.
- 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.
- Click on the Expression tab.
- Enter the
length()
part of the formula.
- Click on the Dynamic Content tab.
- Now choose the dynamic content of the array to count. This will add the references to your expression formula.
- 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!
0 Comments