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

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