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

how to get top {?} records

Status
Not open for further replies.

ddnh

Programmer
Nov 25, 2002
94
US
I have a report (using CR 9) that's bringing in all data for clients sorted by the highest balance. I want to be able to show on the report all clients if no parameter is entered, or show the top # clients (highest balance) based on the parameters entered. How do I accomplish this? By the way, the balance sort is done on the server, so I just need the first {?} records.

I tried to make a count using a running total and called it Rank. In the details x+2 suppress section I put in the formula: IF {?txtTop} <> 0 then {#Rank}>{?txtTop}

this accomplishes the visual aspect...showing only the clients I want to see...but then the totals in the report footer are wrong. it sums all records, even those that are suppressed. so my question is how to get the accurate totals using my current method, or if there exists another method that would be easier altogether?

Show all (no paramter entered):
Rank Client Balance
1 12345 $ 5000.00
2 24354 $ 3500.00
3 54366 $ 2000.00
4 23456 $ 1000.00
5 65745 $ 500.00
Total $12000.00

Show top 3 ({?txtTop}=3) THIS IS WHAT I WANT
Rank Client Balance
1 12345 $ 5000.00
2 24354 $ 3500.00
3 54366 $ 2000.00
Total $10500.00

Show top 3 ({?txtTop}=3) THIS IS MY CURRENT RESULT
Rank Client Balance
1 12345 $ 5000.00
2 24354 $ 3500.00
3 54366 $ 2000.00
Total $12000.00 (it totals suppressed values)
 
Create a parameter with a default value of 9999, or whatever the maximum number of clients you can reasonably expect there to be.

Then conditionally suppress the groups that are greater than the parameter.

Software Sales, Training, Implementation and Support for Exact Macola, eSynergy, and Crystal Reports
 
To get the correct summaries, create two formulas:

//{@sumbal} to be placed in the group header or footer
//(wherever you are displaying the balances):

whileprintingrecords;
numbervar sumbal;

if groupnumber <= {?txtTop} then
sumbal := sumbal + {table.balance};

If the balance is actually a summary per group, replace {table.balance} with the summary.

//{@display} to be placed in the report footer:

whileprintingrecords;
numbervar sumbal;

-LB
 
PS--if the records you display in your example are not groups, but instead are detail records, then use "recordnumber" in the formula instead of "groupnumber."

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top