-
I'm trying to get the top ten for machineno by highest total time they were worked on. Someone suggested using the Top N for my chart in Crystal Reports, but I looked up how to do the Top N and it's not clear on the procedure. So I was wondering if anyone had an example code or report I could reference too? I would appreciate any help.
Thanks Aja
-
Crystal does come with it's own Top N functions but at best they're crap, and at worse they're even crappier. This is what I do;
I use Crystal 7, earlier versions of Crystal may not be able to do this.
First, if you haven't already, set the Sort Order of the report so that the records appear in the order you want.
Somewhere in the group header (or report header), where you want to start counting Top N from create a formula field (called StartCounter) with this formula;
WhilePrintingRecords;
NumberVar MyCount := 0
Somewhere in the details section (where the fields you want to count are, use this formula (call it UpdateCounter)
WhilePrintingRecords;
NumberVar MyCount := MyCount + 1
When you preview the report now you should see the numbers appear in the details section, effectively counting each record.
Once you're happy this is working, right click on the details section to get it's properties, and in the formula box for the "Suppress" option type;
{@UpdateCounter}>10
(I'm not sure if you need the curly brackets- I haven't got Crystal on my home PC)
Now when you preview the report you should find only the top 10 details sections appear. Finally you need to right click on the two formula fields you have created, and select Suppress for both of them.
Note that you must leave them on the report, albeit suppressed, otherwise this won't work.
If this doesn't work let me know and I'll send an example.
[Edited by Buzby on 09-29-2000 at 06:12 PM]