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 / Trying to collect 4000...
Power Apps
Answered

Trying to collect 4000 items, getting error on Sort

(0) ShareShare
ReportReport
Posted on by 920 Super User 2024 Season 1

Hi all,

 

Trying to collect around 4000 items. Getting error Sort has some invalid arguments. Name isnt Valid. Descending isnt recorgnized.

 

getting error on line - Collect(MyTable2, FirstN(Sort(Distinct([@'Test List'],'Control Title'),Descending),2000));

 

Here is my code -

 

Collect(MyTable1, Distinct([@'Test List'],'Control Title'));
Collect(MyTable2, FirstN(Sort(Distinct([@'Test List'],'Control Title'),Descending),2000));
Collect(MyTable, MyTable1, MyTable2)

 

anyone know where Im going wrong?

Categories:
I have the same question (0)
  • Verified answer
    LowCodeJim Profile Picture
    314 Moderator on at

    Hi @wonka1234 ,

     

    Can you confirm where you have "Descending" this is actually from the Enum and evaluates out to "SortOrder.Descending". So your code should actually be:

    Collect(MyTable2, FirstN(Sort(Distinct([@'Test List'],'Control Title'),SortOrder.Descending),2000));

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.
  • wonka1234 Profile Picture
    920 Super User 2024 Season 1 on at

    You are correct! thanks! but whats weird is that is it collecting the same table twice, i want to collec the first 2000 and then the second 2000, do you know where im going wrong?

  • LowCodeJim Profile Picture
    314 Moderator on at

    Hi @wonka1234 ,

     

    Your two statements are doing the same thing, the first gets the first 2000 items (limited by the app settings) then the second is again asking for the FirstN items with N being 2000. Getting large numbers of items from SharePoint can be challenging and if possible I would say you want to design your app so your are querying SharePoint for the items you need. If you do need them all at once though @mdevaney has a post about collecting large collections here that may help: https://www.matthewdevaney.com/create-power-apps-collections-over-2000-rows-with-these-4-tricks/#Collect-Data-In-Chunks-With-For-All-Loops

  • wonka1234 Profile Picture
    920 Super User 2024 Season 1 on at

    @SharePointJB  thanks. Any idea on where im going wrong here? Trying  @mdevaney  solution but getting an error.

     

    getting an error - Filter(MyTable2, Not(ID in MyTable1.ID))) .  'ID' isnt recognized.

     

    full code - 

    Concurrent(
    ClearCollect(
    MyTable1,
    Sort(Distinct([@'Test List'],'Control Title'),SortOrder.Ascending)
    ),
    ClearCollect(
    MyTable2,
    Sort(Distinct([@'Test List'],'Control Title'),SortOrder.Descending)
    )
    );

    ClearCollect(
    MyTable,
    MyTable1,
    Filter(MyTable2, Not(ID in MyTable1.ID)))

  • LowCodeJim Profile Picture
    314 Moderator on at

    Hi @wonka1234 ,

     

    I think it is the distinct function that is causing the issue. This will just be returning a collection with a single column "Value" that contains a distinct list of "Control Titles". I think you would want something like this to get the first  and last 500-2000 (depending on app settings) list items:

    Concurrent(
     ClearCollect(
     MyTable1,
     Sort(
     'Another Test List',
     ID,
     SortOrder.Ascending
     )
     ),
     ClearCollect(
     MyTable2,
     Sort(
     'Another Test List',
     ID,
     SortOrder.Descending
     )
     )
    );
    ClearCollect(
     MyTable,
     MyTable1,
     Filter(
     MyTable2,
     Not(ID in MyTable1.ID)
     )
    )
  • wonka1234 Profile Picture
    920 Super User 2024 Season 1 on at

    @SharePointJB 

     

    I should mention that I need only Control Titles values as I am makin g a collection for that one column only. It will serve as a dropdown values a user selects.

     

    So I got this now - 

     

    Concurrent(
     ClearCollect(
     MyTable1,
     Sort([@'Test List'],'Control Title',SortOrder.Ascending)
     ),
     ClearCollect(
     MyTable2,
     Sort([@'Test List'],'Control Title',SortOrder.Descending)
     )
    );
    
    ClearCollect(
     MyTable,
     MyTable1,
     Filter(MyTable2, Not('Control Title' in MyTable1.'Control Title')));

     

     

     

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 525 Most Valuable Professional

#2
Haque Profile Picture

Haque 273

#3
Kalathiya Profile Picture

Kalathiya 232 Super User 2026 Season 1

Last 30 days Overall leaderboard