Latest Posts

PowerApps get Last record from table or collection


The Last function in Power Apps is used to retrieve the last record from a table or collection. This function is particularly useful when you want to access or display the most recent entry in a dataset, such as the latest transaction, message, or record.

PowerApps – Last() function Syntax

Last(Table)

  • Table: The table or collection from which you want to retrieve the last record.

Notes:

  1. Displaying Recent Entries: Use the Last function to display the most recent entries in a collection, such as the latest messages, transactions, or records.
  2. Dynamic Data Views: Automatically update views to show the last item in a dynamically changing collection.
  3. Data Analysis: Perform analysis on the most recent data points to identify trends or patterns.
  4. Delegation: Be mindful of delegation limits when working with large datasets and ensure the data source supports delegation if necessary.
  5. Error Handling: Ensure that the collection or table is not empty to avoid errors when using the Last function.

PowerApps - Retrieve the Last Record from a Collection

Suppose you have a collection named Products and you want to display the last product in this collection.

  1. Create the Collection:

ClearCollect(Products,

    Table(

        {ProductID: 1, ProductName: "Laptop", Price: 1000},

        {ProductID: 2, ProductName: "Tablet", Price: 500},

        {ProductID: 3, ProductName: "Monitor", Price: 300}

    )

);

  1. Retrieve the Last Record:
    • Add a Label control.
    • Set the Text property of the Label to:

Last(Products).ProductName

This will display "Monitor" because it is the last product in the Products collection.

PowerApps – Get last record from Filtered Collection

Suppose you want to get the last product with a price greater than $400.

  1. Create the Collection:

ClearCollect(Products,

    Table(

        {ProductID: 1, ProductName: "Laptop", Price: 1000},

        {ProductID: 2, ProductName: "Tablet", Price: 500},

        {ProductID: 3, ProductName: "Monitor", Price: 300},

        {ProductID: 4, ProductName: "Keyboard", Price: 100},

        {ProductID: 5, ProductName: "Mouse", Price: 50}

    )

);

  1. Retrieve the Last Record from Filtered Collection:
    • Add a Label control.
    • Set the Text property of the Label to:

Last(Filter(Products, Price > 400)).ProductName

This will display "Tablet" because it is the last product with a price greater than $400 in the filtered Products collection.


We value your Feedback:

Page URL:

Name:

Email:


Suggestion:

© 2024 Code SharePoint