Until recently it was not possible to easily sort arrays or collections of objects in Power Automate using a single expression, either complex logic techniques or Office Scripts were required.
But recently two new handy expressions became available in Power Automate that make it really simple to do:
How the sort expression work
The sort expression accepts either an array with simple values or a collection of objects.
If you pass a simple array to the expression, no parameter is needed. For example, if you have the following array variable with people’s names:
[
"Michel",
"Nick",
"Michael",
"Carlos",
"Renan"
]
By using the sort expression as below:
sort(variables('Names'))
You will get as output:
[
"Carlos",
"Michael",
"Michel",
"Nick",
"Renan"
]
If you have an array/collection with objects, you need to specify a property to use in the sorting, so for example, consider an array variable named ‘NamesCountries’ as below: