Tricky random extract

Tom.Jones

Well-known Member
Joined
Sep 20, 2011
Messages
508
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. Mobile
Hi,

In a table, with 500 rows and 20 columns, of documents that cost 200,000 dollars. How do I extract 25% of these costs to physically check the documents (sort of sampling but random).

Thank you.
 

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.
In column 20 is costs. I need to extract 25% from $ 200,000 (this mean $ 50,000).
Sum of costs of extras documents must be around $ 50,000.
 
Upvote 0
Hey!!!!

All guru from here are in holiday?? :))

Or is to difficult??
 
Upvote 0
Lot of ways to do this. You could add a work column with random numbers in it, then filter by the right value. For example:


ABCD
1ItemValuerandRand
21350.095489>=0.570958207034433
32740.359186
43860.78392
54790.806415
65940.143845
76840.597873
87130.051086
98190.943706
109340.186608
1110130.375809
1211830.094656
1312190.149419
141340.750347
1514320.384563
1615520.697151
1716640.131489
1817470.04358
1918410.821631
2019230.734566
2120160.044384

<tbody>
</tbody>
Sheet8

Worksheet Formulas
CellFormula
C2=RAND()
D2=">="&LARGE(C:C,15)

<tbody>
</tbody>

<tbody>
</tbody>



Put the formula in C2, then copy down. Put the formula in D2, and change the 15 to the number of samples you want. Then select column C, go to the Data tab, Advanced Filtering > Filter in place > and give it a criteria range of D1:D2.


Or you could add the Analysis pack (File > Options > Add-ins > Go (next to Excel Add-ins) > and check the Analysis ToolPak box. Now go to the Data tab > Data Analysis > Sampling > and follow the prompts. Be aware that this tool sometimes will select the record more than once.


Or you could write a VBA macro to do this, but we'd need more information on how your data is laid out.
 
Last edited:
Upvote 0
Thanks for the reply Eric,

I guess I did not explain it well.
In your example, the sum of the numbers in column B is 912.
25% of 912 is 228.
Now I have to find those items in column A whose sum (from column B) is close to 228.

Let say for sum of 228 we have:

Item.......Value

2...........12

5...........8
.....
.....

...........228

We need to list all items and corresponding amount (if their sum is near 228)

Thank you.
 
Last edited:
Upvote 0
What do you consider "close"? Near to 1/4 the total, based on percent, value, standard deviation? How many times to you want to keep looking in search of a closer set?

You can enhance the above example like this:

ABCDEFGHI
1ItemValuerandRandSum25% of sumSample Sum
21350.421379>=0.825376116024242912228226
32740.594056
43860.310353
54790.825376
65940.611129
76840.983807
87130.899614
98190.159377
109340.944097
1110130.382167
1211830.54371
1312190.712575
141340.345105
1514320.133184
1615520.498221
1716640.081112
1817470.429398
1918410.407838
2019230.482752
2120160.869885

<tbody>
</tbody>
Sheet8

Worksheet Formulas
CellFormula
F2=SUM(B:B)
G2
H2=SUMIF(C:C,">="&LARGE($C$2:$C$21,5),B:B)
C2=RAND()
D2=">="&LARGE(C:C,5)

<tbody>
</tbody>

<tbody>
</tbody>

Code:
G2: =F2/4

In this case, you have the additional formulas in F2:H2. Keep pressing F9 (recalculate) until H2 is "close" enough for you. Then you can run the Advanced Filter to show the specific items.


If this doesn't work for you, please specify what "close" means to you. Where is the original data, how many rows and columns in your table. How do you want the results shown? Filtered, highlighted, extract to another sheet? Since you have 2 criteria (count + amount), requiring some iteration, formulas might be tricky. The above method might be your best bet if you want formulas. Otherwise, I could devise a method using the Solver, or write a VBA macro.
 
Upvote 0
Eric,


I can not list items from column A, the sum of which is close to the value in H2.
Can you gave me, a formula, to list - say - in column K, items from column A , which correspond to the numbers in column B whose sum is close to the number in H2.

In column K to be items and in column L to have that numbers.

Thank you.
 
Upvote 0
Like this?


ABCDEFGHIJKLM
1ItemValuerandRandSum25% of sumSample SumIndexItemValue
2a350.539431>=0.7791212509947629122282333c86
3b740.4489126f84
4c860.8193417g13
5d790.6337899i34
6e940.50372520t16
7f840.974036
8g130.850117
9h190.567506
10i340.796396
11j130.637188
12k830.342703
13l190.535796
14m40.190634
15n320.448716
16o520.416354
17p640.339006
18q470.298755
19r410.680239
20s230.134915
21t160.779121

<tbody>
</tbody>
Sheet8

Worksheet Formulas
CellFormula
K2=INDEX($A$2:$A$21,J2)
L2=INDEX($B$2:$B$21,J2)

<tbody>
</tbody>

<tbody>
</tbody>

Array Formulas
CellFormula
J2{=SMALL(IF($C$2:$C$21>=LARGE($C$2:$C$21,5),ROW($C$2:$C$21)-ROW($C$2)+1),ROWS($J$2:$J2))}

<tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try and enter the {} manually yourself

<tbody>
</tbody>







You may want to copy the K:L columns and Paste as Value somewhere else, otherwise the next calculation will change them.
 
Upvote 0
Solution

Forum statistics

Threads
1,214,975
Messages
6,122,538
Members
449,088
Latest member
RandomExceller01

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