Needhelp
(Boonjie)
May 1, 2020, 12:55pm
1
Hi,
I am trying to select random rows from an excel document (e.g. 100 rows i need 30 random rows) and copy it over to another excel file. Currently i am trying AsEmunerable but it only gives me the first 30 rows.
Is there anything wrong with this or is there any alternative solutions.
ppr
(Peter Preuss)
May 1, 2020, 8:40pm
2
@Needhelp
As an alternate you can create a list of Index numbers like this
With the distinct we do run till we got 30 unique index values.
The rows can be selected with: RandomList.Select(Function (x) DataTableVar.Rows(x)).CopytoDataTable
2 Likes
Needhelp
(Boonjie)
May 2, 2020, 9:02am
3
HI,
Do you have the workflow?
Thanks alot for the help!
ppr
(Peter Preuss)
May 2, 2020, 12:46pm
4
@Needhelp
Find starter help for generating the random Index numbers here:
Needhelp.xaml (6.0 KB)
@Needhelp
Give this a try:
PickRandomRows.zip (29.7 KB)
1 Like
HKF
August 22, 2021, 6:06pm
6
This is really helpful
Is there away to select the number of records that I want to randomly select?
Lets say I want 30 from the whole population
Hi @HKF ,
In the code attached, you’ll find an argument called “_countRowsToPick_in”. You’ll have to set it to how many rows you’d like to randomly select.
HKF
August 24, 2021, 5:53am
8
Thanks a lot your file is really helpful
My report has 300 records
I put the number to be randomly selected is 5
Most of times it get me 5
But sometimes I get 4
Sometimes I get 3
Do you know how to fix this
That’s true.
I made some adjustments to the code, give it a try: PickRandomRows_v2.zip (11.4 KB)
2 Likes
This was extremely helpful for me in a similar process. Thank you.