cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
yashp1196
Frequent Visitor

Reverse an Array

Does anyone how to reverse an array?

Ex. [Alert 4, Alert 3, Alert 2, Alert 1] -> [Alert 1, Alert 2, Alert 3, Alert 4] 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Rhiassuring
Super User
Super User

Hi there, 

 

You can use an Excel script to do that - that would be the most efficient way.  Paul Murana walks through that here, in his "Array Reverse" script.

https://www.tachytelic.net/2021/03/power-automate-sort-array/

If you're not into that, this works too:

 

Rhiassuring_0-1656739486565.png

 

1. Create a new array (I called mine arrBackwards)
2. Use an "Apply to Each" and point it at your original collection.

3. Get the last item in the Forwards array:  last(variables('arrForwards'))

4. Add it to the Backwards array.

5. Remove the last item from the Forwards array. take(variables('arrForwards'),add(length(variables('arrForwards')),-1))
6. Set the Forwards array to the previous compose so we reference that going forward.

 

 

That did the trick.

 

______________________________________________________________


Did this answer your question? Please mark it as the solution.
Did it contribute positively towards finding the final solution? Please give it a thumbs up.

I answer questions on the forum for 2-3 hours every Thursday!



View solution in original post

3 REPLIES 3
Rhiassuring
Super User
Super User

Hi there, 

 

You can use an Excel script to do that - that would be the most efficient way.  Paul Murana walks through that here, in his "Array Reverse" script.

https://www.tachytelic.net/2021/03/power-automate-sort-array/

If you're not into that, this works too:

 

Rhiassuring_0-1656739486565.png

 

1. Create a new array (I called mine arrBackwards)
2. Use an "Apply to Each" and point it at your original collection.

3. Get the last item in the Forwards array:  last(variables('arrForwards'))

4. Add it to the Backwards array.

5. Remove the last item from the Forwards array. take(variables('arrForwards'),add(length(variables('arrForwards')),-1))
6. Set the Forwards array to the previous compose so we reference that going forward.

 

 

That did the trick.

 

______________________________________________________________


Did this answer your question? Please mark it as the solution.
Did it contribute positively towards finding the final solution? Please give it a thumbs up.

I answer questions on the forum for 2-3 hours every Thursday!



Excellent, thank you for this, very helpful.  Love your username btw! 🙂

Tester3
Regular Visitor

If anyone is still facing this issue, Power Automate now also has a reverse expression that you can use inside the compose function. See this blog for an explanation: https://www.inogic.com/blog/2022/10/new-function-expressions-in-power-automate-flow/

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Community Calls Conversations

Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Users online (1,436)