Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

Trying to collect 4000 items, getting error on Sort

(0) ShareShare
ReportReport
Posted on by 909 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?

  • wonka1234 Profile Picture
    909 Super User 2024 Season 1 on at
    Re: Trying to collect 4000 items, getting error on Sort

    @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')));

     

     

     

  • LowCodeJim Profile Picture
    279 Super User 2025 Season 1 on at
    Re: Trying to collect 4000 items, getting error on Sort

    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
    909 Super User 2024 Season 1 on at
    Re: Trying to collect 4000 items, getting error on Sort

    @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
    279 Super User 2025 Season 1 on at
    Re: Trying to collect 4000 items, getting error on Sort

    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
    909 Super User 2024 Season 1 on at
    Re: Trying to collect 4000 items, getting error on Sort

    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?

  • Verified answer
    LowCodeJim Profile Picture
    279 Super User 2025 Season 1 on at
    Re: Trying to collect 4000 items, getting error on Sort

    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.

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,702 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,017 Most Valuable Professional

Leaderboard