Extract random list with criteria excel

IceSnakeR

New Member
Joined
Aug 4, 2017
Messages
13
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi all,

I have been doing a lot of research in the last two weeks and it seems I cannot find an adequate solution for my need. I have attached a photo with a replica of the sheet I am using, in my file I have a lot more rows (about 12000 rows). The information in column C:C are unique sale id's, the information in column D:D is a list of names (about 89 names) that will repeat. I need to extract randomly a list of sale ID but I don't want to receive as a result two or more sale IDs for the same name as it is shown in the photo bellow.

I was able to find a formula that extracts the random list based on a value that I manually insert in cell D3 where I specify how many sale ID to extract. I was able to achieve this with the formula >>> =INDEX(SORTBY(C3:C31,RANDARRAY(ROWS(C3:C31))),SEQUENCE(D3)) <<< in cell E3 which correctly extracts the random sales id. The column F:F is not required; I am using it to perform an xlookup to understand if a sale person appears twice in the list.

Thank you in advance,
Chris
 

Attachments

  • Capture.PNG
    Capture.PNG
    37.3 KB · Views: 16

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
This should do it:

Book1
ABCDEFG
1
2PersonID
3JOHN1238JOHN307
4ADAM146JULIE422
5MARY169MARY169
6JANE192JANE744
7JOANNE215JOANNE215
8JULIE238MACK261
9MACK261ADAM698
10LUCY284LUCY284
11JOHN307
12ADAM330
13MARY353
14JANE376
15JOANNE399
16JULIE422
17MACK445
18LUCY468
19JOHN491
20ADAM514
21MARY537
22JANE560
23JOANNE583
24JULIE606
25MACK629
26LUCY652
27JOHN675
28ADAM698
29MARY721
30JANE744
31JOANNE767
Sheet2
Cell Formulas
RangeFormula
F3:G10F3=LET(x,B3:C31,y,SORTBY(x,RANDARRAY(ROWS(x))),z,TAKE(y,,1),TAKE(FILTER(y,XMATCH(z,z)=SEQUENCE(ROWS(x))),E3))
Dynamic array formulas.


The idea here is to first sort the entire array randomly, filter the result based on 1st occurences of the names in the 1st column and take the appropriate amount of rows from the top of this filtered array.
 
Last edited:
Upvote 0
Solution
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
This should do it:

Book1
ABCDEFG
1
2PersonID
3JOHN1238JOHN307
4ADAM146JULIE422
5MARY169MARY169
6JANE192JANE744
7JOANNE215JOANNE215
8JULIE238MACK261
9MACK261ADAM698
10LUCY284LUCY284
11JOHN307
12ADAM330
13MARY353
14JANE376
15JOANNE399
16JULIE422
17MACK445
18LUCY468
19JOHN491
20ADAM514
21MARY537
22JANE560
23JOANNE583
24JULIE606
25MACK629
26LUCY652
27JOHN675
28ADAM698
29MARY721
30JANE744
31JOANNE767
Sheet2
Cell Formulas
RangeFormula
F3:G10F3=LET(x,B3:C31,y,SORTBY(x,RANDARRAY(ROWS(x))),z,TAKE(y,,1),TAKE(FILTER(y,XMATCH(z,z)=SEQUENCE(ROWS(x))),E3))
Dynamic array formulas.


The idea here is to first sort the entire array randomly, filter the result based on 1st occurences of the names in the 1st column and take the appropriate amount of rows from the top of this filtered array.
Hi JvdV, this works for me. Thank you!
 
Upvote 0

Forum statistics

Threads
1,223,099
Messages
6,170,114
Members
452,302
Latest member
TaMere

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top