One of my team members asked about filtering an array by Index in Power Automate. Unfortunately, Power Automate does not have a built-in option to get the index of an item within an array. But there are ways to do this.
In this tutorial, I will show you how to filter an array by index using Power Automate with a few more examples:
- Filter Array by Specific Indexes using Power Automate
- Filter the First item from an Array by Index value in Power Automate
- Get the Last Item in an Array using a Filter Array Index in Power Automate
Filter Array Based on Specific Index in Power Automate
Suppose you have an array with multiple objects as shown in the code below. You want to filter the multiple array objects based on a specific index.
Let’s assume you want to filter out objects 1 and 3 from the array.
[
{
"TaskID": "T001",
"TaskName": "Create Power Platform PDF",
"Status": "Pending"
},
{
"TaskID": "T002",
"TaskName": "Develop Site Page",
"Status": "Pending"
},
{
"TaskID": "T003",
"TaskName": "Create a Web Part",
"Status": "In Progress"
},
{
"TaskID": "T003",
"TaskName": "Create a Site Page",
"Status": "Completed"
}
]You can achieve this by using the steps below in Power Automate.
- Create a Power Automate Instant cloud flow that can be triggered manually by clicking a button.
- After that, add an “Initialize variable” action to store the array value. Enter a name for a variable, take the type as an array, and a value.

Power Automate does not have a built-in way to get the index of an item from any array. So, we need to create an index manually to filter the array items based on specific indices.
- For that, add one more “Initialize variable” action that will assign the index to each item in the array. Set the parameters as below.
- Name: Provide a name for a variable. I have named it “index”.
- Type: Select type as ‘Integer’.
- Value: Set the value to ‘0’.

- Then, take another “Initialize variable” action with an empty array. This will store the array items with the appended indexes. Provide the parameters, such as Name, Type (as Array), and Value, as shown below.

- Then add the “Apply to each loop” action to loop through each item in an array variable. Select an output from the previous steps to: Initialize variable [Tasks].

- Inside the loop, add an “Append to array variable” action to append the index value to each item when the loop runs each time. Set the properties:
- Name: Select the Empty Array variable from the previous steps [VarIndexedArray].
- Value: Insert the below expression.
{
"Task": "@{item()?['TaskName']}",
"Task Status": "@{item()?['Status']}",
"index": "@{variables('index')}"
}
- Next, add an “Increment variable” action, which will increment the variable count of the index. Select [index] variable from options and Value to ‘1‘.

At this point, the Indexed array will look like the following format:
[
{
"Task": "Create Power Platform PDF",
"Task Status": "Pending",
"index": "0"
},
{
"Task": "Develop Site Page",
"Task Status": "Pending",
"index": "1"
},
{
"Task": "Create a Web Part",
"TaskStatus": "In Progress",
"index": "2"
},
{
"Task": "Create a Site Page",
"Task Status": "Completed",
"index": "3"
}
]- Now, let’s add a “Filter Array” action outside of the loop, which will filter the items with indices 1 and 3. Make sure to set the parameters.
- From: Choose to add the Initialize variable with an empty array [VarIndexedArray].
- Filter Query: Click on Edit in advanced mode -> Provide the below expression.
or(equals(int(item()?['index']), 1), equals(int(item()?['index']), 3))
The flow is ready now. Let’s save and run it manually.
- When the flow runs successfully without any errors, open and check the Filter Array Outputs. It will show the Array objects whose index values are 1 and 3.

This is how to filter items in an array based on specific indexes using Power Automate.
Check out Filter an Array by Multiple Conditions in Power Automate
Get the First Item from an Array by Index in Power Automate
To illustrate this example, I will use the array mentioned above, where I want to filter the first item from the given array.
From the image below, you can see the Array Input. The highlight mark represents the first item of an array.

You can follow the same steps mentioned in the above example, but change the Filter Query expression in the Filter Array action.
The index of an array item starts with Zero. To get the first item from an array by index value, use the expression present in the table below.
| Choose Value | Operator | Choose Value |
|---|---|---|
| int(item()?[‘index’]) | is equal to | 0 |

This will filter and get the first item from any array of objects using the Filter Array action in Power Automate.
Save and run the flow.
Output:

Check out How to Filter an Array by Another Array in Power Automate?
Get the Last Item from an Array by Index using Filter Array in Power Automate
You can also get the last item from any array with the help of an index position using the filter array action in Power Automate.
The image below shows the Array with multiple objects. The highlighted item represents the last item of an array.

Follow the same steps mentioned in Example 1, and then update the filter query expression as shown below.
- Add a “Filter Array” action and set the required parameters.
- From: Take the VarIndexedArray variable from the previous action.
- Filter Query: Insert the below expression.
| Choose Value | Operator | Choose Value |
|---|---|---|
| int(item()?[‘index’]) | is equal to | sub(length(variables(‘VarIndexedArray’)),1) |
Since the array is zero-indexed, subtract one from the length of the array.

Output:
Take a look at the reference image, which displays the last item from an Array.

I recommend using the first() and last() functions if you only want to retrieve the first and last items from an array, rather than using the Filter array action.
In this tutorial, you have learnt how to filter an array by indexes in Power Automate using the filter array action.
I hope you found this article helpful. Do mention your suggestions or comments in the comments section.
You may like the following Power Automate tutorial:
- Merge Arrays in Power Automate
- Power Automate Array Variable
- Power Automate Get Items Filter Query
- Power Automate Filter Query If Blank

After working for more than 18 years in Microsoft technologies like SharePoint, Microsoft 365, and Power Platform (Power Apps, Power Automate, and Power BI), I thought will share my SharePoint expertise knowledge with the world. Our audiences are from the United States, Canada, the United Kingdom, Australia, New Zealand, etc. For my expertise knowledge and SharePoint tutorials, Microsoft has been awarded a Microsoft SharePoint MVP (12 times). I have also worked in companies like HP, TCS, KPIT, etc.