Introduction
In Power Apps, the Index function is used to retrieve a specific item from a collection or table based on its position (row number). It is particularly useful when you want to:
Access a single record from a list or table.
Dynamically pick items based on user input.
Work with ordered data like tasks, products, or menu items.
Unlike Excel, where functions often start from row 1 automatically, Power Apps tables are also 1-based, meaning the first item is at position 1.
Here is the Index-related functions in Power Apps
| Function | Purpose | Returns | Example |
|---|
Index(Table, Position) | Gets a specific record by row number | Single record | Index(EmployeeList, 2) |
First(Table) | Gets the first record | Single record | First(EmployeeList) |
Last(Table) | Gets the last record | Single record | Last(EmployeeList) |
FirstN(Table, Number) | Gets first N records | Table (multiple records) | FirstN(EmployeeList, 3) |
LastN(Table, Number) | Gets last N records | Table (multiple records) | LastN(EmployeeList, 2) |
Key Characteristics
Table-based: Works on collections or tables.
Position-specific: Returns a single row at the specified index.
Dynamic: Can be combined with Filter, SortByColumns, or user input to select items dynamically.
1. Syntax of Index Function
In Power Apps, there isn’t a function literally named Index() like Excel, but you can use LookUp, FirstN, or Last functions to mimic an index-based selection. However, in recent versions, Power Apps added Index as a property of galleries or data tables:
Index(Table, RowNumber)
Power Apps tables are 1-based, meaning the first item is at position 1.
2. Using Index with a Collection
Let’s create a collection first:
ClearCollect(
EmployeeList,
[
{ID: 1, Name: "Person1", Role: "Manager"},
{ID: 2, Name: "Person2", Role: "Developer"},
{ID: 3, Name: "Person3", Role: "Designer"}
]
)
Get the 2nd Item Using Index
Set(
SecondEmployee,
Index(EmployeeList, 2)
)
3. Using Index in a Gallery
Suppose you have a Gallery called Gallery1 that displays EmployeeList. You can access a specific row like this:
Gallery1.AllItems[2]
Gallery1.AllItems[IndexNumber].Name
Where IndexNumber is a variable or number indicating which row you want.
4. Using Index with FirstN and Last
If your Power Apps version doesn’t support Index directly:
Last(FirstN(EmployeeList, 2))
This returns the 2nd item in the EmployeeList collection.
Explanation: FirstN(EmployeeList, 2) gives first 2 items → {Person1, Person2}
Then Last(...) picks the last item → {Bob}
5. Example: Display Employee Name by Index
Add a Text Input for user to enter index (e.g., TextInput1) and a Label to show the employee name:
Label.Text = Index(EmployeeList, Value(TextInput1.Text)).Name
Scenario: Task Tracker – Get the Next Task
Suppose you have a collection of tasks with ID, Task Name, Priority, and Status, and you want to display the next pending task based on the order in the collection.
1. Create the Collection
ClearCollect(
TaskList,
[
{ID: 1, TaskName: "Design UI", Priority: "High", Status: "Completed"},
{ID: 2, TaskName: "Write Backend", Priority: "Medium", Status: "Pending"},
{ID: 3, TaskName: "Test App", Priority: "High", Status: "Pending"},
{ID: 4, TaskName: "Deploy App", Priority: "Low", Status: "Pending"}
]
)
2. Dynamic Index Example
We want to get the first pending task:
Set(
FirstPendingIndex,
Index(
Filter(TaskList, Status = "Pending"),
1
)
)
Filter(TaskList, Status = "Pending") → filters only pending tasks.
Index(..., 1) → picks the first pending task in the filtered list.
Now FirstPendingIndex will hold:
{ID: 2, TaskName: "Write Backend", Priority: "Medium", Status: "Pending"}
3. Show in a Label
Label.Text = "Next Task: " & FirstPendingIndex.TaskName & " (Priority: " & FirstPendingIndex.Priority & ")"
Output:
Next Task: Write Backend (Priority: Medium)
4. Let User Pick Nth Pending Task
Add a Text Input (TextInput1) where user types 2 to see the 2nd pending task:
Set(
SelectedPendingTask,
Index(
Filter(TaskList, Status = "Pending"),
Value(TextInput1.Text)
)
)
And in a label:
Label.Text = "Selected Task: " & SelectedPendingTask.TaskName
Conclusion
The Index function lets you pick a specific item from a table or collection by its position. It’s simple, dynamic, and works well with filtered or sorted data. Perfect for selecting tasks, menu items, or any ordered list, making your apps more interactive and efficient.