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 / Sorting an Array of Ob...
Power Automate
Answered

Sorting an 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.

 

The sort is performed as below:

RedBI_2-1691683584597.png

The expression in the screenshot is:

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

 

The result looks like this:

RedBI_4-1691684012994.png

 

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

[0.21,0.39]

[0.21,0.44]

[0.21,0.63]

 

Please help? I think this might be a weird float/rounding issue, but 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)
  • RedBI Profile Picture
    19 on at

    Resubmitted here https://powerusers.microsoft.com/t5/Building-Flows/Nested-sort-functions-on-array-of-objects-results-out-of-order/m-p/2292732 because automarked as spam. Apologies for the double posting.

  • creativeopinion Profile Picture
    10,502 Super User 2025 Season 2 on at

    @RedBI This is the expression I used. I put your array into a Compose action.

     

     

    sort(sort(outputs('Compose'), 'BoundingBoxleft'), 'BoundingBoxtop')

     

     

    This is the output result:

     

     

    [
     {
     "BoundingBoxtop": 0.21,
     "BoundingBoxleft": 0.3
     },
     {
     "BoundingBoxtop": 0.21,
     "BoundingBoxleft": 0.39
     },
     {
     "BoundingBoxtop": 0.21,
     "BoundingBoxleft": 0.44
     },
     {
     "BoundingBoxtop": 0.21,
     "BoundingBoxleft": 0.63
     },
     {
     "BoundingBoxtop": 0.22,
     "BoundingBoxleft": 0.3
     },
     {
     "BoundingBoxtop": 0.22,
     "BoundingBoxleft": 0.39
     }
    ]

     

     

     

    Hope this helps!


    If I helped you solve your problem—please mark my post as a solution ✅.
    Consider giving me a 👍 if you liked my response!

    👉Watch my tutorials on YouTube
    👉Tips and Tricks on TikTok

     

  • Verified answer
    RedBI Profile Picture
    19 on at

    Thank you @creativeopinion ,  but I'm not sure why your sort() expression functions as expected and mine doesn't.

     

    I think I ended up solving my issue though, in a roundabout way. Thanks to @lbendlin (again, sorry all for the double posted request)

     

    I converted the [x,y] decimals into integer-strings (0.24 = '24') and then placed them in a composite key by concatenating them with a decimal point such that [x,y] becomes 'y.x'. Then converted that to a float and sorted by that number.

     

    In other words, I turned the [x,y] coordinates [0.21,0.39] into 39.21. This let me sort as desired. I still don't understand why my nested sort didn't work but this was an effective workaround.

     

    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 503 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 321 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard