Skip to main content

How to Get the First Record of a Table in Power Apps with First

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

When every record of a table holds the same value, any of them will do, and the first is the easiest to get. First returns a table's first record, and a dot after it reads one of its columns.

Syntax​

Syntax
First(Table)
One column of the first record
First(Table).Column
PartWhat it is
TableThe table to take the first record from.
ColumnA column of that record, to read one value.

From Microsoft's First reference:

  • First returns the first record of a table, and Last the last.
  • FirstN and LastN return several records, as a table, even when you ask for one.
  • Index(Table, n) returns the record at position n, counting from 1, so First(Table) is the same record as Index(Table, 1).
  • With a data source, these functions aren't delegated: Power Apps fetches the first part of the data and applies the function to that.

The example is the list of people on the Reports screen of the Overtime Timesheet app. It groups a month's approved entries by email, so each person gets one card. The name to show on the card is on every one of their entries.

Step 1: Read the Name from the First Entry​

In the gallery's Items, AddColumns adds an Employee column to each group, from its first entry (How to Add a Column to a Table in Power Apps with AddColumns):

Part of galPeopleRS → Items
AddColumns(
GroupBy(locRowsRS, Email, Rows),
Employee, First(Rows).Employee
)
  • First(Rows) is the group's first entry.
  • .Employee reads its name.

A group always has at least one entry, because GroupBy makes groups only from records that exist, so First always has a record to return here.

The whole formula, as Studio shows it, also lists each person's departments and adds up their hours:

The formula bar with the Items property of the gallery: If, IsBlank of locRowsRS, Blank, then Sort of AddColumns of GroupBy of locRowsRS by Email into Rows, with Employee as First(Rows).Employee, Departments as Concat of Distinct of the Rows' Department, and Hours as the Sum of Rows' Hours, sorted by Hours in descending order

Step 2: Show It​

On the card, the name label's Text is ThisItem.Employee (How to Use ThisItem in a Power Apps Gallery).

The Result​

Each card shows the person's name, read from their first entry:

The Approved hours by person list on a phone with four cards: Admin User with 10.00 hours in Emergency Department, on one line and Radiology on the next in a taller card, then Aisha Khan 4.00 hours in Emergency Department, Maya Patel 3.75 hours in Radiology and Daniel Brooks 2.50 hours in Radiology

Common Mistakes​

MistakeWhat happensDo this instead
First where the records hold different valuesYou get whichever record happens to be firstSort the table first, or use LookUp with a condition
FirstN to get one recordIt returns a table, not a recordFirst
Last on a large data sourceIt returns the last of the records Power Apps fetched, not of the whole listSort the other way in the data source and use First

Troubleshooting​

SymptomLikely causeFix
The value is blankThe table has no records, or the column is empty in the first recordCheck the table; IsEmpty(Table) tells you if it has none
A delegation warningFirst on a data sourceWork on a table already in the app, or filter in the data source first

FAQ​

What's the difference between First and LookUp?​

LookUp returns the first record that meets a condition. First returns the first record, whatever it holds.

First or Index?​

First(Table) and Index(Table, 1) return the same record. Microsoft's reference says Index returns an error when the table is empty.

Can I read several columns of the first record?​

Yes. Each First(Table).Column reads one. To read several without repeating First, keep the record with With and read its columns from there (How to Use the With Function in Power Apps).

Conclusion​

First(Table) returns a table's first record, and First(Table).Column one value from it. Inside a grouped table, it reads a value every record of the group shares, such as a person's name.

Additional Resources​