Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random sampling

Status
Not open for further replies.

lauriesamh

Technical User
Sep 1, 2004
119
US
Hi,
I need to pull a random sample (210) of orders out of over 46,000. I would like to split the sample between two subgroups (M & H). Can anyone help?
 
Create a formula:

rnd()

Add this to your detail section and sort by it. Then insert a running total {#cntwingrp} which counts any recurring field, evaluates for each record, and resets on change group (Your M/H field).

Then go to the section expert->detail->suppress->x+2 and enter:

{#cntwingrp} > 105

Ido Millet has an FAQ on this topic that you might want to check out also.

-LB
 
Ido's almost works... problem is that for each order there are random detail records (example 3 records for 1 order)... is there a way I could do this based on the grouping of the order ID?

You are great!
 
What you might do is to insert a maximum on {@rnd} at the order ID group level. Then instead of using suppression, go to report->group sort->topN: 105->choose "maximum of @rnd" as your sort field.

I'm not sure whether this would actually meet the technical criteria for random if by virtue of having more detail records an Order ID tended to be more likely to have a higher maximum or something. I'm not sure about the probability theory...

-LB
 
Step 1:
Place the following formula (@Random_Number)
in the detail section:
---------------
Rnd()
---------------

Create another 2 formulas of:

Group header:
whileprintingrecords;
numbervar Row:=0

Details
whileprintingrecords;
numbervar Row:=Row+1

Step 2:
Sort the records by @Random_Number (ascending).

Step 3:
In the suppress attribute of the detail section enter the following expression:
whileprintingrecords;
numbervar Row;
Row > ({?Show_N_Records}/2)

Looks about right

-k
 
SV,

That's the equivalent of my first suggestion. The issue is that the selection is meant to be on a group for order ID instead of the details.

-LB
 
In your main report, show only orders.
For each order you are showing, use a subreport to show the detail.

Cheers,
- Ido

view, e-mail, export, burst, distribute, and schedule Crystal Reports.
 
Sounds good. I'll give it a try!
To confirm...I would put the
@GroupHeader on the order ID
@Details and @RandomNumber in the details in the subreport?
Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top