How to Reverse an Array in Power Automate?

A few days ago, one of my team members asked me to reverse an array using Power Automate. I used the Power Automate reverse() function, which changes the arrangement of array elements in reverse order.

In this tutorial, I will explain how to reverse an array in Power Automate and show how to reverse an array of items from the SharePoint list column.

Power Automate reverse() Function

The reverse() function in Power Automate converts the order of items in a collection in reverse order.

Power Automate, reverse function output, will be the updated collection in reverse order.

InputOutput
Lidia, Jhon, RoseRose, Jhon, Lidia

Reverse an Array in Power Automate

Now, let’s begin by implementing the examples of reversing items from an array using Power Automate cloud flow.

Dig in to know more!

Example 1:- [Using Power Automate Instant cloud flow]

InputOutput
Power Automate, Power BI, Power AppsPower Apps, Power BI, Power Automate

Follow the steps below:

1. Open the Power Automate Home page, click + Create, select the Instant cloud flow, provide the flow name, choose the flow trigger (manually trigger a flow), and Click the Create button.

2. Take an Initialize Variable flow action to create an array of elements. Configure the details below:

  • Name: Enter a name for the variable.
  • Type: Select variable type as ‘Array‘.
  • Value: Insert the below expression here.
createArray('Power Automate','Power BI','Power Apps')

You can replace the elements with the elements you need.

How to reverse an array in Power Automate

3. Add a Compose flow action to reverse the created array.

Inputs: Click on Expression -> Insert the below code.

reverse(variables('Power Platform'))
Reverse an array using Power Automate

4. The flow is ready now. Click on Save. Test it Manually. Select the Runflow button. The screenshot below represents the reverse order of an array’s elements in the compose flow action.

How to reverse a string array in Power Automate

This is how to reverse an array in the Power Automate flow using the reverse() function.

Check out How to Replace Value in an Array in Power Automate

Example 2:- [Reverse SharePoint List column items]

In this example, I will show you how to reverse an array of SharePoint list column item values using a Power Automate flow.

Scenario:

Suppose I have taken a SharePoint list [Leave Request] with a set of names in a list column[Employee Name], as shown below.

I wanted to reverse the Employee Name column values.

Power Automate reverse array items

Below are the steps to do this example:

1. Create an Instant cloud flow in Power Automate.

2. Add the Get Items action to retrieve all the SharePoint list items. Fill in the required details:

  • Site Address: Provide a SharePoint site.
  • List Name: Choose a SharePoint list from the drop-down.
How to reverse items from an array using Power Automate

3. Take the Initialize Variable flow action. Provide a Name and select the data type as ‘Array‘.

How to reverse items from an array with Power Automate

4. Next, add Append to array variable flow action to append the list column values in an array.

Configure the details given below:

  • Name: Select the variable name from the drop-down.
  • Value: Take the Employee Name from dynamic content.

Then, For each loop will be added automatically.

Reverse an array using Power Automate flow

5. Then, add a Compose flow action to reverse the list column values. Provide the below expressions in the Inputs section.

reverse(variables('Employee Name'))
Reverse an array from a given position in Power Automate

6. Once the Power Automate flow is ready, save and run the flow manually. If there is no error, the flow runs successfully. Now, open the compose flow action to check the output.

It will display the elements of an array in reverse order, starting with the last element [Employee Names].

Reverse an array with Power Automate reverse() expression

This is all about reversing an array of items with the Power Automate reverse() expression.

Conclusion

I trust that this tutorial provided you with a clear understanding of reversing an array of elements using the Power Automate reverse() function.

You may also like:

>

Build a High-Performance Project Management Site in SharePoint Online

User registration Power Apps canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App

Power Platform Tutorial FREE PDF Download

FREE Power Platform Tutorial PDF

Download 135 Pages FREE PDF on Microsoft Power Platform Tutorial. Learn Now…