Power Apps  

How to Use the Index Function in Power Apps

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

FunctionPurposeReturnsExample
Index(Table, Position)Gets a specific record by row numberSingle recordIndex(EmployeeList, 2)
First(Table)Gets the first recordSingle recordFirst(EmployeeList)
Last(Table)Gets the last recordSingle recordLast(EmployeeList)
FirstN(Table, Number)Gets first N recordsTable (multiple records)FirstN(EmployeeList, 3)
LastN(Table, Number)Gets last N recordsTable (multiple records)LastN(EmployeeList, 2)

Key Characteristics

  1. Table-based: Works on collections or tables.

  2. Position-specific: Returns a single row at the specified index.

  3. 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)
  • Table – The collection or table you want to access.

  • RowNumber – The numeric position of the row (starting at 1).

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)
)
  • SecondEmployee will now hold:

    {ID: 2, Name: "Person2", Role: "Developer"}

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]
  • This gets the 2nd item in the gallery.

  • You can also bind a label in the gallery:

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
  • If the user types 3, it will show Charlie.

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
  • Typing 2Selected Task: Test App

  • Typing 3Selected Task: Deploy App

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.