web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Nested sort() function...
Power Automate
Unanswered

Nested sort() functions on array of objects - results out of order

(0) ShareShare
ReportReport
Posted on by 19

I am trying to sort an array of objects, but the result seems incorrect - a few of the items in the final array appear out of order.

 

The sort is performed as below:

RedBI_0-1691763393452.png

 

The expression in the screenshot is:

sort(sort(first(body('Select')),'BoundingBoxleft'),'BoundingBoxtop')

 

The result looks like this:

RedBI_1-1691763393502.png

 

 

The red arrow indicates how I think the nested sort(sort()) 'should' work - the coordinate values should be sorted as:

[0.21,0.39]

[0.21,0.44]

[0.21,0.63]

 

Please help? Please forgive me if I've missed something obvious.

 

 

 

Additional context:

For reference, I'm trying to fix a broken 'AI builder' OCR output - it reads values from a PDF out of order. Instead of reading like a human would, it outputs a piece of text on e.g. "Line 2" of a document wedged between the values taken from "Line 1"

 

Example (not actual text from a document):

Line 1: "Sally jumped far,"
Line 2: "but Bill jumped farther"

Becomes:

Line 1: "Sally jumped jumped far farther",
Line 2: "but Bill"

 

 

The BoundingBox top/left values are essentially just [x,y] coordinates that describe positions of text in the document (I have redacted the associated text values from the array in the screenshot). I have rounded the float values (e.g. 0.2063754848 whatever) to 2 decimal places with the expression:

 float(formatNumber(<value>,'0.00')) 

And then map them into an array of objects using a Select statement.

 

I then try to stash these in a variable, sorted as described above. Please let me know if you can help.

Categories:
I have the same question (0)
  • Verified answer
    lbendlin Profile Picture
    8,474 Super User 2025 Season 2 on at

    Sorting only happens on a single field. You will need to create a composite key and sort on that one.

  • RedBI Profile Picture
    19 on at

    Thank you! I don't really understand why a nested sort doesn't work, but a composite key helped. It took me a moment to understand what you meant but I made a composite key < y.x > out of [x,y] by converting for e.g. the original decimal coordinates [0.21,0.39] into the float value 39.21. This let me sort as desired when added to the array produced by my Select statement.

     

    I used the expression:

    float(concat(string(mul(float(formatNumber(item()['BoundingBox']['top'],'0.00')),100)),'.',string(mul(float(formatNumber(item()['BoundingBox']['left'],'0.00')),100))))

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard