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 / Select random items fr...
Power Apps
Answered

Select random items from collection

(0) ShareShare
ReportReport
Posted on by 119
Hello folks,
 
I have 100 records in my collection and want to randomly select any 5, 10 or 30 records and display them in the PowerApps canvas gallery.

Can somebody explain how we can choose any random items from the collection?
I have the same question (0)
  • Suggested answer
    SaiRT14 Profile Picture
    1,990 Super User 2025 Season 2 on at
    Hi   , Pls try the following:
     
    Use the AddColumns function to add a new column to your collection with a random value for each record. ClearCollect(
        colWithRandom,
        AddColumns(
            colOriginal,
            "RandomValue",
            Rand()
        )
    );
     
    Use the Sort function to sort the collection by the RandomValue column. ClearCollect(
        colSortedRandom,
        SortByColumns(
            colWithRandom,
            "RandomValue",
            Ascending
        )
    );
     
    Use the FirstN function to select the desired number of random records. ClearCollect(
        colRandomSubset,
        FirstN(
            colSortedRandom,
            10 // Replace with 5, 30, or any other number
        )
    );
     
    Set the Items property of the gallery to the colRandomSubset collection: Items: colRandomSubset
    --------------
     
    If you want the user to dynamically specify the number of records (e.g., 5, 10, or 30): 
    ClearCollect(
        colRandomSubset,
        FirstN(
            colSortedRandom,
            Value(TextInput_NumRecords.Text) // Use the value from the input
        )
    );
     
    hope this helps.
     
  • Verified answer
    AndrianaO Profile Picture
    213 Moderator on at
    Hi! You can try this formula
     
    Set(recordsNumber,5);
    ClearCollect(colRandom,FirstN(Shuffle(originalCollection),recordsNumber));
     
    where colRandom is a random collection to display in your gallery, recordsNumber is number of records in that collection, originalCollection is your original collection with 100 records
     
    Let me know if this works! 

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 721 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard