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 / Need to know alternati...
Power Apps
Unanswered

Need to know alternative for FOR loop (not ForAll).

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi,

 

I am looking to write simple loop that can do something like below. I am unable to find any matching articles on internet or poweruser forum.

 

For i=1 to 10

Next

 

or 

 

For (int i=0; i<10; i++)

{ }

 

Purpose of this is to use Rand function to pickup random set of data and create custom collection. Here is what is the scenerio.

 

Sharepoint List A has around 200 records. Data is grouped and i need to pickup multiple set of data.

 

2 collection based on above 200 records need to be created based on below parameters. 

Collection X will have 20 records

Collection Y will have 10 records.

 

Above count will vary based on user input on screen. Based on Parameter selection on screen, records in X can be anything between 2 to 50 and same is the case for Y.

 

I need to randomly pickup records and populate into collections X and Y.

 

Please suggest solution.

 

Thanks

Priyank

Categories:
I have the same question (0)
  • timl Profile Picture
    36,780 Super User 2026 Season 1 on at

    Hi Priyank,

     

    If you just want to assign a random number to each row, you can accomplish this by calling the AddColumns function like so.
     

    ClearCollect(DataCollection, AddColumns(YourSharePointList, "RandomValue", Rand()))


    This formula adds a column called RandomValue to YourSharePointList and saves the result to a collection called DataCollection.

    To return 20 random records, you can sort the collection by RandomValue and return the top 20 records. The formula to do this, and to store the result in a collection called DataCollection20Random would look like this.

     

    ClearCollect(DataCollection20Random,FirstN(SortByColumns(DataCollection, "RandomValue"),20))

    You can obviously replace 20 with the value that the user enters on screen.

    The alternative would be to build a task in Flow to carry out the job.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi @timl,

     

    Do you know any sample that can help me using Flow to manipulate data and i can use it in PowerApps?

     

    Thanks

    Priyank

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!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 547

#2
WarrenBelz Profile Picture

WarrenBelz 444 Most Valuable Professional

#3
Valantis Profile Picture

Valantis 322

Last 30 days Overall leaderboard