Pulling a 5% sample from a table

iosiflupis

New Member
Joined
Jan 26, 2022
Messages
39
Office Version
  1. 365
Platform
  1. Windows
Hello all,

I have a table that will have over 800 records when done. We need to be able to select a RANDOM 5% sample for auditing. The data that we will be using to determine selection will be in column A:A (Tracking Number). I have been looking at RANDOM, RANDBETWEEN, and INDEX. I also searched the library here, seeing that most of the results were using VBA. I would like to stay away from VBA if possible as I will not be the only one using this tabel.

The table has columns A - O, but as I stated column A is where the unique information resides.


Thank you all,
Joseph Carney
 

Attachments

  • mrexcel screenshot 10-7-22.png
    mrexcel screenshot 10-7-22.png
    38.2 KB · Views: 10

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
This can be one way. I have used multiple columns to show you the steps.

But the idea is
  • to add two helper columns
  • In First Column we put RANDOMBETWEEN(1,Total Cases)
  • Then Copy and Paste Values of that column in that column itself.
  • Sort Data by this new column
  • Add another column which selects 5% of cases top to bottom based on number calculated in a cell
  • You get most random 5% cases to audit.
Try it, if it works for you. it took me just 2 minutes to do

All Records.xlsb
ABCDEF
1IDRandomPasteValueTo Audit1
2ID 02811Yes
3ID 03033No
4ID 03344No
5ID 02655No
6ID 03655No
7ID 02566No
8ID 03466No
9ID 02077No
10ID 0111111No
11ID 0131111No
12ID 0051212No
13ID 0021313No
14ID 0271313No
15ID 0371313No
16ID 0211414No
17ID 0011515No
18ID 0321717No
19ID 0311818No
20ID 0071919No
21ID 0092121No
22ID 0082222No
23ID 0142222No
24ID 0182222No
25ID 0222222No
26ID 0122424No
27ID 0152424No
28ID 0192424No
29ID 0172525No
30ID 0242929No
31ID 0393030No
32ID 0033131No
33ID 0063131No
34ID 0233131No
35ID 0103232No
36ID 0163434No
37ID 0383535No
38ID 0353737No
39ID 0043838No
40ID 0293939No
Sheet7
Cell Formulas
RangeFormula
F1F1=INT(COUNTA(Table43[ID])*5%)
B2:B40B2=RANDBETWEEN(1,COUNTA([ID]))
D2:D40D2=IF(COUNTA($C$2:C2)<=$F$1,"Yes","No")
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A2:A40Expression=D2="Yes"textNO
 
Upvote 0
In this case, I have 100 records in column A.
MrExcelPlayground12.xlsx
ABC
1Tracking NumberAudit
210001012
310011030
410021060
510031082
610041083
71005
81006
91007
101008
111009
121010
131011
141012
151013
161014
171015
181016
191017
201018
211019
221020
231021
241022
251023
261024
271025
281026
Sheet24
Cell Formulas
RangeFormula
C2:C6C2=LET(b,COUNT(A:A),r,RANDARRAY(b,1,0,1,FALSE),a,INDEX(A:A,SEQUENCE(b,1,2)),SORT(INDEX(SORTBY(a,r),SEQUENCE(0.05*b))))
Dynamic array formulas.
 
Upvote 0
Solution
another option if yo have the new TAKE function.
Fluff.xlsm
ABC
1Tracking NumberAudit
210001118
310011198
410021246
510031108
610041094
710051048
810061286
910071211
1010081239
1110091277
1210101250
1310111163
1410121162
1510131005
1610141197
171015
181016
191017
201018
211019
221020
231021
241022
251023
261024
271025
281026
291027
301028
Data
Cell Formulas
RangeFormula
A2:A301A2=SEQUENCE(300,,1000)
C2:C16C2=LET(f,FILTER(A2:A1000,A2:A1000<>""),TAKE(SORTBY(f,RANDARRAY(ROWS(f))),ROWS(f)*0.05))
Dynamic array formulas.
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,810
Messages
6,121,690
Members
449,048
Latest member
81jamesacct

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