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

Notifications

Announcements

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:
I have the same question (0)
  • RandyHayes Profile Picture
    76,297 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
    68,697 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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard