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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select last 5 records 2

Status
Not open for further replies.

Jillp

Technical User
Jun 7, 2001
75
US
I have various quantities of detail lines in a group.

I would like to select only the last 5 records in each group.

There are no distinguishing factors on the detail lines.
(The dates vary from group to group. There may be 3 records in one group and 25 in the next.)

There must be a way to find the last record and count backwards.....but I can't find it.

Thanks for any help!

Jill

 
Declare a shared variable to use as a counter (in a formula) like this:

Shared NumberVar x;
x := x + 1;

Insert that formula in the details field and suppress it.
Then put this formula in the group header (and suppress it, also):

Shared NumberVar x;
x := 0;


Now, right click on the details field and click 'format section'. Then click the suppress formula button (to the right of the suppress button) and type:

Shared NumberVar x;
x > 5;

Then hit OK (of course). Then, if 'x>5' is true, then the details will be suppressed! Let me know if this doesn't work or if it's not what you were trying to do... -rodbac
 
Jill,

This is almost exactly like rodbac's but will display records in a group if less than 5

Create the following 2 formulas...

Name:
InitializeCounter

Code:
WhilePrintingRecords;
numbervar Counter := 0

Put InitializeCounter in the GroupHeaderSection and
suppress so it does not display

Name:
Counter

Code:
WhilePrintingRecords;
numbervar Counter := Counter + 1

Put Counter in the DetailSection and
suppress so it does not display

Now right-click any field on your detail line and insert a summary field. You want to select Count from the dropdown.

Suppress the resulting summary field in the GroupFooter so it does not display.

In FormatDetailSection click on the formula icon next to suppress and add the following code...

whileprintingrecords;
{@Counter} < (InsertTheSummaryFieldHere)- 4)


Jase

 
Thanks to you both. Your info saved my day!

Jill
 
I now have a new problem.

How can i total/average/min/max etc only the records i have chosen?

I am getting totals on all details.

thanks,

jill
 
You would have to use the same condition in running total
formulas

Create a new formula called Total (or something)
Add...

whileprintingrecords;
if ({@Counter} < (InsertTheSummaryFieldHere)- 4) then
numbervar Total := Total //don't add anything
else
numbervar Total := Total + YourNumericFieldValue

If you want by group then make sure you create an Inialization formula and insert in GroupHeader.


 
Jase,

This works great for a 'running total'.

How would I average my chose detail lines?



 
Create a new formula called Records(or something)
Add...

whileprintingrecords;
if ({@Counter} < (InsertTheSummaryFieldHere)- 4) then
numbervar Records := Records //don't add anything
else
numbervar Records := Records + 1


Create another formula field called Average and
add..

whileprintingrecords;
@Total/Records


Put this formula in your Report Footer Section or if by group, in the Group Footer Section but remember to...

If you want by group then make sure you create an Inialization formula and insert in GroupHeader.


 
This is great! thanks alot for your help. Jill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top