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!

Displaying a Random Sample (number or proportion)

Report Development

Displaying a Random Sample (number or proportion)

by  IdoMillet  Posted    (Edited  )
If you need to randomly select and display a given number of records, or a user-specified proportion of the records, here's a simple approach:

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

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

Step 3:
In the suppress attribute of the detail section enter the following expression:

3.1 If you need to display a given number of Records:
----------------------------------------
RecordNumber > {?Show_N_Records}
----------------------------------------
where {?Show_N_Records} is a parameter allowing the user to
specify the number of records to be shown.

3.2 If you need to display a given proportion of Records:
----------------------------------------
RecordNumber > ({?Show_X_Percent}/100) * Count({some_field})
----------------------------------------
where {?Show_X_Percent} is a parameter allowing the user to
specify a number between 0 and 100.

Cheers,
- Ido

CUT, Visual CUT, and DataLink Viewer:
view, e-mail, export, burst, distribute, and schedule Crystal Reports.
www.MilletSoftware.com
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top