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!

How do I rank a column in a Crystal Reports Crosstab?

Status
Not open for further replies.

fanhokie

Programmer
Jan 24, 2012
2
US
I want to rank from highest to lowest 31 counties in a crosstab but keep the counties in alphabetical order. Is there any easy way to add a ranking column to their totals?

Crystal Reports Crosstab

County Total Rank
1 200 3
2 500 2
3 100 4
4 700 1
5 50 5

I would like the rank to show up like above but cannot figure out how to do it?

Thanks
C
 
If you are willing to place the crosstab in the report footer, the following works. In the main report, insert a group on county and add the following formula to your county group header (The group sections and detail sections can be suppressed if you wish):

whileprintingrecords;
numbervar array x;
numbervar a := a + 1;
redim preserve x[a];
x[a] := sum({table.value},{table.county});

Create another formula {@ordervals} and place it in Report footer_a:
WhilePrintingRecords;
numbervar Array x;
numbervar Array result;
redim preserve result[ubound(x)];
Numbervar b;
NumberVar c;
numbervar i;
numbervar array y;
numbervar array z;

for b := 1 to ubound(x) do
(
result := Maximum(x);
for c := 1 to ubound(x) do
(
if x[c] = result then
(
x[c] := 0;
Exit For;
);
);
);

for i := 1 to ubound(result) do (
redim preserve y;
y := result;//-i for ascending order; i for descending order.
redim preserve z;
z := i
);


Then create a formula {@0}:

whilereadingrecords;
0

Add this as your second summary field in the crosstab and in the customize style tab, check "horizontal summaries" and "add label".

Next, select your first(original) summary in an inner cell of the crosstab->right click->format field->suppress->x+2 and enter:

whileprintingrecords;
numbervar curr := currentfieldvalue;
false

Then select the summary for {@0} in an inner cell->right click->format field->display string->x+2 and enter:

whileprintingrecords;
numbervar curr;
numbervar array y;
numbervar array z;
numbervar d;
numbervar i;
for i := 1 to ubound(y) do(
if y=curr then
d := z
);
totext(d,0,"")

This will display the rank for the summary.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top