Skip to content
Home » LastN function in Power Apps

LastN function in Power Apps

The LastN function in Power Apps is used to return the last n records from a table or collection.

It helps you retrieve a specific number of records from the end of a data source, based on the number of records you specify.

Syntax:

LastN(Source, NumberOfRecords)
  • Source: The table or collection from which you want to retrieve records.
  • NumberOfRecords: Optional. The number of records you want to retrieve from the end of the source. If you do not specify this argument, the function returns one record from last.

Usages of LastN function

Displaying the Last N records in a Gallery

You can use the LastN function to show only the last n records in a gallery.

As you can see, the gallery is displaying records from the collection named colEmpData, with a total of 7 records shown

Let’s use the LastN function to display the last 4 records from the collection colEmpData in a gallery.

Go to the Item property of Gallery and write below formula.

LastN(
    colEmpData,
    4
)

The formula looks at the colEmpData collection and retrieves the last 4 records based on the order of records in the collection.

You can see, the gallery displays the last 4 records from the collection.

 

Note if you do not provide the second argument NumberOfRecords value in the LastN function, it will return last one record from table/collection.

As you can see in the formula below, we did not specify the number of records to be returned from the collection in the LastN function, which results in it returning only the last one record from the collection

LastN(
  colEmpData
)

Fetching the Last n records from a Table

If you only want to get the last records from a table, you can use LastN with 5 as the number of records.

 LastN(Employees, 5)

This formula returns the last 5 records from the Employees table.

When to use LastN functon

  • The LastN function is useful when you need to fetch a specified number of records from the end of a table or collection in Power Apps. It allows you to focus on recent or final entries in a data source efficiently.
  • If you want to display the least-performing records (e.g., the bottom 10 sales), you can use the LastN function to retrieve those records based on the sort order applied to your data

 

Read Also..

Loading

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from SQL BI Tutorials

Subscribe now to keep reading and get access to the full archive.

Continue reading