Have you ever tried to sort an array or collection in Power Automate?
The sort function in Power Automate
Did you ever look for the Sort function when you build your expressions?
You can stop searching! It doesn’t exist. There is no easy way to sort an array. But it is not impossible to sort your array.

To filter an array is easy, as there is an action for that, but sorting can be a real pain.
The Sort an array Azure Function
You could however create an Azure function. Only recently the option to create Powershell v2 functions Apps can be created in Azure.

You can of course do similar thing in C# but, isn’t PowerShell a lot easier?
Once the function has been created you will get the following example:

The above code needs to be adjusted so that my json is received and sorted and then returned.
The above code I’m replacing with:
using namespace System.Net
# Input bindings are passed in via param block.
param($Request, $TriggerMetadata)
# Write to the Azure Functions log stream.
Write-Host "PowerShell HTTP trigger function processed a request."
# Interact with query parameters or the body of the request.
$myArray = $Request.Query.MyArray
if (-not $MyArray) {
$myArray = $Request.Body.MyArray
}
if ($myArray) {
$myArrayObj = ConvertFrom-JSON $myArray
$mySortedArrayObj = $myArrayObj | Sort-Object -Property Title
$body = ConvertTo-Json $mySortedArrayObj
$status = [HttpStatusCode]::OK
}
else {
$status = [HttpStatusCode]::BadRequest
$body = "Please pass a json on the query string or in the request body."
}
# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
StatusCode = $status
Body = $body
})
The Flow

The first Compose contains the following unsorted json collection:
[{Title:'Title 1', Description:'Description 1'},
{Title:'Title 3', Description:'Description 3'},
{Title:'Title 2', Description:'Description 2'},
{Title:'Title 5', Description:'Description 5'},
{Title:'Title 4', Description:'Description 4'}]
The second Compose validates my json. This isn’t really needed but always good to do during tests like this.
Then the 3rd Compose returns the result.

Hi Pieter,
Me again! Though I have figured out my flow, but I have some crazy ideas, not sure if they can be accomplished in Flow.
#1 Filter Query in ODATA query, while use key eq ‘key’, can I do something like trim(tolower()) in both sides? Otherwise I have to do this in the source data;
#2 After this filter, it will be apply to each, can I join the results to one array? I tried Compose/Select/Set Variable…nothing worked….
#3 Is it a crazy idea to do bulk update/create in a shared spreadsheet? – My concerns are all about the source data control, the Flow is not difficult.
Many thanks,
Vera
Hi Vera,
Please have a look at this post: https://veenstra.me.uk/2018/11/12/microsoft-flow-filter-queries-in-sharepoint-get-items/
I’m listing most of the options available. The options available are a bit limited. So you might just have to go for best possible and then filter with loops after that.
Thank you Pieter, yes, I read that 3 times…really limited options.
[…] while back I wrote about how to sort an array in Power Automate and I used an Azure function to do the job. One of the annoying things of that approach is that you […]