Skip to content

Latest commit

 

History

History
93 lines (66 loc) · 2.05 KB

File metadata and controls

93 lines (66 loc) · 2.05 KB

1️⃣ First / Last

Category: Data | Works in: Canvas Apps


Overview

First returns the first record from a table; Last returns the final record. Commonly used after Filter or Sort to retrieve one specific row.


Syntax

First( Table )
Last( Table )

Simple Examples

1. First product in list

First(Products)

2. Latest order for user

First(Sort(Filter(Orders, CustomerEmail = User().Email), OrderDate, SortOrder.Descending))

3. Oldest open task

First(Sort(Filter(Tasks, Status = "Open"), DueDate, SortOrder.Ascending))

Complex Examples

4. Safe First with IsEmpty guard

If(
    !IsEmpty(varSearchResults),
    Set(varTopResult, First(varSearchResults)),
    Notify("No results.", NotificationType.Warning)
)

5. Date range header from data

With(
    { sorted: Sort(varData, Date, SortOrder.Ascending) },
    Text(First(sorted).Date, "dd MMM") & " – " & Text(Last(sorted).Date, "dd MMM yyyy")
)

6. Get latest record after Patch (audit pattern)

Set(varNewRec, Patch(Events, Defaults(Events), { Title: txtTitle.Text, CreatedOn: Now() }));
// varNewRec IS the new record — equivalent to First(Sort(Events,CreatedOn,SortOrder.Descending))

Best Practices

  • Validate inputs before using in write operations.
  • Combine with related functions for complete workflows.
  • Test with both empty and populated data sources.
  • Consider delegation when working with large data sets.

Related Functions

Function Relationship
Filter Related function
Sort Related function
LookUp Related function
IsEmpty Related function

🔗 Official Documentation

First, Last – Microsoft Learn


Back to Home | Power Apps Formulas Reference | Last updated: May 2026