Random Selection in Excel With Conditions

Copper Contributor

Hello All,

 

I have a task required in Excel that I need to do monthly and I know someone smarter than me has a better way of getting it done.  Any help?

 

I need to pull a defined set of random unique ID numbers after meeting a few criteria.

 

The table below is small and completely randomized.  My real tables are more than 180,000 rows so imagination is important here.

 

Report 10 random ID# for each STATE that equal both Red & Sprockets.  Also, separately, report 5 random ID# for each STATE that equal both Blue & Cogs.

IDState IndustryRed or Blue
1CASprocketsGreen
2AZCogsBlue
3CTSprocketsRed
4ARSprocketsBlue
5COSprocketsGreen
6AKCogsRed
7FLCogsGreen
8CTSprocketsBlue
9CASprocketsRed
10DECogsRed
11COCogsGreen
12GACogsBlue
13AKCogsRed
14GASprocketsBlue
15AZSprocketsGreen
16DECogsGreen
17FLCogsBlue
18ARSprocketsRed

 

Currently, the way I have to do this is filter out and remove all rows where the Color does not =Red or Blue.

Then I use =RAND to assign a random number to any column and copy paste the values.  I use multiple sort to sort the table first by Random Value and State and Industry. 

Then, I filter my list by Cogs and Red and then for each State I select the first 10 IDs, switching the State filter each time.

Repeat those steps again for Blue Cogs.

 

Ideas?

 

There has to be a way for me to say, "Report the ID number of ten random Red Sprockets and five random Blue Cogs.

 

Thanks y'all.  Curious to see what someone can come up with.

 

Travis

1 Reply

@HeyBaby_QuePaso  Here is an example of 1 option.  

mtarler_0-1653665274004.png

in the attached I create a N randomized filtered list of the Table based on the 3 criteria (state, industry, color). see attached.