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

Top N Sort

Status
Not open for further replies.

crystalreport85

Programmer
Sep 27, 2010
51
CA
My question is user will pass the N value. Taking that value and sort the record by TOP N .

How to accomplish it?
For ex:
user passes 10 to see only top 10 records at a time
later 5 to see only top 5 recs ..

Is it possible to do in crystal?
Thank you
 

Create the parameter to prompt the user for the N value. In the group sort set up the Top N as usual, you can leave the default value in, and in the X2 formula just select the parameter. It will then ignore the default value.

 
Thank you for the reply. Could you please explain? what to do with the formula x2? should we put the @x2 in the group sort N input field.
Thank You
 

Yes, sorry - you're not actually creating a standalone formula, you're just entering {?YourParameter} in the X2 next to the Top N value in the group sort expert.

Once you get it working you'll see that the numeric value is updated each time you refresh the report with a different parameter value.
 
Thank you againg
I am using crystal report 8.5. I don't see X2 next to Top N. May be because of my version..or I am looking at the wrong place.
 

Probably not available in 8.5; don't have it in front of me to verify. Is it working when you enter a static value such as top 5?

If so, I'll work on a manual method to accomplish this unless someone else does it first.

 

Assuming your summarized field is in GF1, put this formula in GF1:

//{@Counter}
whileprintingrecords;
numbervar x;
x := x + 1

In the Section Expert, place this formula in the suppression X2 for both GH1 and GF1:

{@Counter} > {?Your Parameter} * 2


Keep in mind that Top N via Group Sort is really group suppression, and that's what these formulas do also. Therefore any running totals and grand totals will have to be done via formulas, since the normal summaries will include suppressed values.

If you're not sure what I mean take a look at the record count without any Top N applied. Then refresh using a Top N value, and look at the record count - it will be the same.

 
If there is only one group, you can use:

groupnumber > {?N}

If there is more than one group, you can place Brian's formula in the group header and then use a section suppression formula of:

whileprintingrecords;
numbervar x;
x > {?N}

-LB
 
Thank you Brain and lbass
Great !lbrass method worked for me since I am using one group
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top