web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Delegable workaround f...
Power Apps
Unanswered

Delegable workaround for FirstN or LastN

(0) ShareShare
ReportReport
Posted on by 41

Are there any known/recommended workarounds for the FirstN or LastN functions?

All of my searches bring up basic delegation info or the 500/2000 collection size limit.


Thanks.

Categories:
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @jblane 

    First there is no collection size limit.  There is a row limit to the number of rows allowed to be returned from a datasource at any given query, but that is not a collection limit.

     

    So, the key to working around delegation is to first Filter the amount of records you want to perform FirstN / LastN or any other non-delegable function.  If you can, within your FirstN apply a filter to the datasource that will return a smaller number of rows, then the outer functions will not be impacted.

     

    Example:   FirstN(Filter(myData, Status="Active"), 100)

    If I know that there will never be more than 2000 Status="Active" records, then this will filter the rows and return a list of less than that and the FirstN will be just fine.

    Note: this will STILL give you a delegation warning.  If you know your data is in limits, then you can ignore.

    If you hate seeing the warning, you can change to this formula:

        FirstN(AddColumns(Filter(myData, Status="Active"), "Annoy", false), 100)

     

    I hope this is helpful for you in your design.

     

  • Pstork1 Profile Picture
    69,665 Most Valuable Professional on at

    I agree with everything @RandyHayes said, but let me add one extra possibility when working with FirstN() or LastN().  Sort() and SortByColumn() are both delegable functions.  So if you can't figure a way to Filter() the list you can sort it so that the records you want are at the top of the list.  Then you can use FirstN() without worrying if you only need 500-2,000 records.  LastN() can be accomplished the same way by sorting the records in reverse order and using FirstN().

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 220 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 194 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 150

Last 30 days Overall leaderboard