PowerApps First, FirstN, Last, and LastN function with examples - SPGuides (2024)

by Bijay Kumar

PowerApps First, FirstN, Last, and LastN function with examples - SPGuides (1)

In this PowerApps Tutorial, We will see what is PowerApps First, FirstN function, Last and LastN function. What are the syntaxes of each function? Also, by taking some simple scenarios, We will see how to use all these functions in PowerApps app.

Table of Contents

PowerApps First and FirstN Function

First, let us discuss on PowerApps First and FirstN function with an example.

  • PowerApps First is a function that will return the first item of a data source or a table.
  • PowerApps FirstN is a function that helps to return the first set of records of a table whereas the second argument defines the number of records that to be returned.
  • The First function returns a single record or an item whereas the FirstN function returns a table.
  • Although if you specify only a single record, then the FirstN function returns a table.

Syntax:

Below represents the syntaxes of PowerApps First and FirstN function.

Syntax-1:

First( Table )

Where,

Table = This is required. You need to specify the table name to operate on.

Syntax-2:

FirstN( Table [, NumberOfRecords ] )

Where,

  1. Table = This is required to specify the table name to operate on.
  2. NumberOfRecords = This is an Optional that will help you to return the Number of records. If you will not specify this argument, then the function will return only one record or item.

Also, check out, PowerApps CountRows function.

PowerApps First and FirstN Function Example

Here we will discuss how we can use PowerApps First and FirstN function by taking a simple scenario.

  • The below screenshot represents a SharePoint List named Travel Details. This list has a number of columns with different data types. Also, it has these many below records as shown below.
  • Out of these many records, I want to retrieve one or some of the records using the PowerApps First and FirstN function.
PowerApps First, FirstN, Last, and LastN function with examples - SPGuides (2)
  • On the PowerApps screen, Insert a Vertical Gallery Control and set its Layout property as Title and subtitle.
  • Select the gallery control and apply this below formula on its Items property as:
Items = First('Travel Details')

Where,

‘Travel Details’ = SharePoint List Name

  • Once you will preview the app, you can view the first record in the gallery control as shown in the below screenshot.
PowerApps First, FirstN, Last, and LastN function with examples - SPGuides (3)
  • Similarly, if you want to view set of records i.e. suppose you want first four records from that specific SharePoint list, then apply this below formula on Gallery controls Items property as:
Items = FirstN('Travel Details', 4)

Where,

4 = Number of records that you want to display in the gallery control

  • Once you will preview the app, you can view the first four records in the gallery control as shown in the below screenshot.
PowerApps First, FirstN, Last, and LastN function with examples - SPGuides (4)

This is how we can use the First and FirstN Function in PowerApps.

PowerApps Last and LastN Function

Let us see how to use the Last and LastN Function in PowerApps.

  • PowerApps Last is a function that will return the last item or record of a data source or a table.
  • PowerApps LastN is a function that helps to return the last set of records of a table whereas the second argument defines the number of records that to be returned.
  • The Last function returns a single record or an item whereas the LastN function returns a table.
  • Although if you specify only a single record, then the LastN function returns a table.

Syntax:

Below represents the PowerApps Last and LastN function syntaxes:

Syntax-1:

Last( Table )

Where,

Table = This is required to specify the table name to operate on.

Syntax-2:

LastN( Table [, NumberOfRecords ] )

Where,

  1. Table = This is required to specify the table name to operate on.
  2. NumberOfRecords = This is an Optional that will help you to return the Number of records. If you will not specify this argument, then the function will return only one record or item.

NOTE:

When you used with the data source, then all these functions can’t be delegated. You can get only the first portion of the data source and then the function applied.
When the data source item crosses the limits, then a warning may appear to remind you of the PowerApps Delegation.

PowerApps Last and LastN Function Example

  • Suppose, you want to view the Last record from the above SharePoint list named Travel Details.
  • In the same way, Insert a Vertical Gallery control and set its Items property as:
Items = Last('Travel Details')
  • When you will save and preview the app, you can see the last item details in the gallery control as shown below.
PowerApps First, FirstN, Last, and LastN function with examples - SPGuides (5)
  • Similarly, To retrieve some of the last records, you can apply this below formula on Gallery control’s Items property as:
Items = LastN('Travel Details', 4)

Where,

4 = Number of records that you want to display in the gallery control

  • Once you will preview the app, you can view the last four records in the gallery control as shown in the below screenshot.
PowerApps First, FirstN, Last, and LastN function with examples - SPGuides (6)

This is how we can use the Last and LastN Function in PoweApps.

First vs FirstN expression in PowerApps

In this example, We will see what is the difference between PowerApps First and FirstN function.

  • Below represents a SharePoint List named Travel Details. This list has a column named “Driver“.
  • Here, I want to get the 3rd record (of Driver column only) from the specified list i.e. Nagaraj.
PowerApps First, FirstN, Last, and LastN function with examples - SPGuides (7)
  • Here the problem is When I am using the First function to get the first value, the output returns as the expected value. Not only the first function but also the Last function returns the last value.
  • But when I am using the below syntax as FirstN, then it generates an error as: “Expected Text Value“. That means the property on this control expects text values.
  • I have applied the formula on Label control’s Text property as:
Text = FirstN('Travel Details', 3).Driver

Where,

  1. ‘Travel Details’ = SharePoint List Name
  2. Driver = SharePoint List Column name that will retrieve the 3rd name

You can see the error in this below screenshot. Follow the below things to resolve the issue.

PowerApps First, FirstN, Last, and LastN function with examples - SPGuides (8)
  • First of all, to clarify this type of issue, you need to understand properly the difference between First, First N, Last and LastN functions in PowerApps.
  • The PowerApps First Function helps to retrieve the first record whereas the Last Function retrieves the last record from your data source. The return result is a single record.
  • But the FirstN function is used to return the first set of records of a table and the LastN function returns the last set of records. The returned result is always a table only.
  • To resolve the above issue, you can use this below formula on Label’s Text property as:
Text = Last(FirstN('Travel Details', 3)).Driver
  • Now Save and Preview (F5) the app. You can see the value of the 3rd record (Driver value i.e. Nagaraj) as shown in the below screenshot.
PowerApps First, FirstN, Last, and LastN function with examples - SPGuides (9)

Also, you may like these below PowerApps Tutorials as:

  • PowerApps LastSubmit() with Examples
  • PowerApps AddColumns Function with Examples
  • PowerApps Patch Function with examples
  • PowerApps ForAll Function with examples
  • PowerApps if statement with examples
  • PowerApps Replace Function with examples
  • PowerApps Pen input control (PowerApps signature)
  • PowerApps Employee Directory
  • How to add PowerApps app to Microsoft Teams – Step by Step
  • PowerApps SharePoint Lookup Column + PowerApps Dropdown Example
  • PowerApps Barcode Scanner – Detailed tutorial
  • How to build multilingual app in PowerApps

In this PowerApps Tutorial, We saw what is PowerApps First, FirstN function, Last and LastN function. What are the syntaxes of each function? Also, by taking some simple scenarios, We discussed how to use PowerApps First, FirstN, Last and LastN functions.

PowerApps First, FirstN, Last, and LastN function with examples - SPGuides (10)

Bijay Kumar

I am Bijay a Microsoft MVP (10 times – My MVP Profile) in SharePoint and have more than 17 years of expertise in SharePoint Online Office 365, SharePoint subscription edition, and SharePoint 2019/2016/2013. Currently working in my own venture TSInfo Technologies a SharePoint development, consulting, and training company. I also run the popular SharePoint website EnjoySharePoint.com

PowerApps First, FirstN, Last, and LastN function with examples - SPGuides (2024)
Top Articles
Latest Posts
Article information

Author: Annamae Dooley

Last Updated:

Views: 5858

Rating: 4.4 / 5 (65 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Annamae Dooley

Birthday: 2001-07-26

Address: 9687 Tambra Meadow, Bradleyhaven, TN 53219

Phone: +9316045904039

Job: Future Coordinator

Hobby: Archery, Couponing, Poi, Kite flying, Knitting, Rappelling, Baseball

Introduction: My name is Annamae Dooley, I am a witty, quaint, lovely, clever, rich, sparkling, powerful person who loves writing and wants to share my knowledge and understanding with you.