Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Automate - Building Flows
Answered

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

(1) ShareShare
ReportReport
Posted on by 103

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

  • Suggested answer
    SteveFeldman Profile Picture
    73 on at
    Sorting Array Data Descending and Ascending with multiple columns in Power Automate
     @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'
    )

     
     
  • naidu1811 Profile Picture
    103 on at
    Re: Sorting Array Data Descending and Ascending with multiple columns in Power Automate

    Thankyou @Chriddle 

  • Verified answer
    Chriddle Profile Picture
    7,791 Super User 2025 Season 1 on at
    Re: Sorting Array Data Descending and Ascending with multiple columns in Power Automate

    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
     }
    ]

     

     

     

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

Michael Gernaey – Community Spotlight

We are honored to recognize Michael Gernaey as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard >