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!

Help! with Dynamic TopN and Tie 1

Status
Not open for further replies.

alvieklaud

Programmer
Apr 5, 2011
5
PH
Anyone know how to Create a formula that can show ties of the dyanmic TopN. To better explain this here's an example

Name no.of Visits
Name A 38
Name B 29
Name C 18
Name D 18
Name E 18
Name F 17
Name G 17
Name H 16

Ok so got the code down to where i can dyanmically change the Top for example Top 3 would include A,B and C. Now come the part that im stuck, C, D and E have a No. of visits of 18 so they should be include in the Top 3. so my report should show A, B, C, D, and E for top 3 can anyone help?.

i just supress the group footer x-2 and put in this formula, groupnumbers>{?topN} (topN) is my parameter.
 
Oh and i forgot another thing. There should be a ranking column.

Name No.of Visits Ranking
Name A 38 1
Name B 29 2
name C 18 3
Name D 18 3
Name E 18 3
Name F 17 4
Name G 17 4
Name H 16 5

i don't know how to do the ranking. please help thanks o and No.of Visits Column are calculated in crystal reports
 
Can you clarify whether you are using a group on Name or whether this in a crosstab? What version of CR are you using?

-LB
 
Lb
I have them on a group by name, what I did was suppressed the details section and display them on the footer. Using CR version 8.5
 
Instead of using topN, choose "All" in the group sort, descending order. Then create a number parameter {?N} and then create a formula for the group section:

whileprintingrecords;
numbervar dcnt;
numbervar cnt := cnt + 1;
numbervar curr;
numbervar prev := curr;
curr := Count ({table.visits}, {table.name});
if groupnumber = 1 or
curr <> prev then
dcnt := dcnt + 1 else
dcnt := dcnt;

The dcnt that appears will act as the rank.

Then go into the section expert ->group footer->suppress->x+2 and enter:

whileprintingrecords;
numbervar dcnt;
numbervar cnt;
numbervar lastdcnt;
if cnt = {?N} then
lastdcnt := dcnt;
cnt > {?N} and
dcnt > lastdcnt;

-LB
 
Thanks Lb, modified the formula a bit and it works, thanks for the help,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top