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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Sorting Array Data Des...
Power Automate
Answered

Sorting Array Data Descending and Ascending with multiple columns in Power Automate

(1) ShareShare
ReportReport
Posted on by 109

Sort an array by Score in descending order and then by ResponseTimeInSec in ascending order using Power Automate.


Example Input Array Data
Score             ResponseTimeInSec

1000             12
2000              8
2000             20
Expected Output
After applying the sorting, your output should look like this:

Score                ResponseTimeInSec

2000                 8
2000                20
1000                12

Categories:
I have the same question (0)
  • Verified answer
    Chriddle Profile Picture
    8,665 Super User 2026 Season 1 on at

    Just sort 2 times (and reverse the sort results):

     

    reverse(
    	sort(
    		reverse(
    			sort(
    				json(
    					concat(
    						'[',
    							'{"Title": "Item 0", "Score": 2001, "RTime": 12},',
    							'{"Title": "Item 1", "Score": 2000, "RTime": 11},',
    							'{"Title": "Item 2", "Score": 2001, "RTime": 10},',
    							'{"Title": "Item 3", "Score": 2000, "RTime": 9},',
    							'{"Title": "Item 4", "Score": 2001, "RTime": 8},',
    							'{"Title": "Item 5", "Score": 2000, "RTime": 7},',
    							'{"Title": "Item 5", "Score": 2001, "RTime": 6}',
    						']'
    					)
    				),
    				'RTime'
    			)
    		),
    		'Score'
    	)
    )

     

     

    Result:

     

    [
     {
     "Title": "Item 5",
     "Score": 2001,
     "RTime": 6
     },
     {
     "Title": "Item 4",
     "Score": 2001,
     "RTime": 8
     },
     {
     "Title": "Item 2",
     "Score": 2001,
     "RTime": 10
     },
     {
     "Title": "Item 0",
     "Score": 2001,
     "RTime": 12
     },
     {
     "Title": "Item 5",
     "Score": 2000,
     "RTime": 7
     },
     {
     "Title": "Item 3",
     "Score": 2000,
     "RTime": 9
     },
     {
     "Title": "Item 1",
     "Score": 2000,
     "RTime": 11
     }
    ]

     

     

     

  • naidu1811 Profile Picture
    109 on at

    Thankyou @Chriddle 

  • Suggested answer
    SteveFeldman Profile Picture
    77 on at
     @Chriddle  I have found the sort function to be unreliable when embedding them in this manner.  PAuto does not maintain the integrity of the original row order.  Therefore i use the following technique.  I add a new column in the array concatenating the fields:
      { "itemKey" :  concat( column1Name, '|', column2Name, '|', column3Name }
     
    In addition to eliminating the issue I was facing , sorting once usually saves time over multiple embedded sorts.   You can also use formation to build in reverse sorts into the key:
     
    sort(
      json(
        concat(
          '[',
          '  {"itemKey" : "',concat(formatNumber(Score,'0000'),'|',formatNumber(sub(100, RTime),'000')), '|"Title": "Item 0", "Score": 2001, "RTime": 12}]'
                                                         etc.
          )
        ),
      'itemKey'
    )

     
     

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Automate

Last 30 days Overall leaderboard