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

Count for Top N

Status
Not open for further replies.

rajasan77

Programmer
Jan 12, 2010
30
US
I have to find the count for TOP N. N is any number.

For example, If I have to find the top 10 diagnosis used by doctor, I know how to find the top 10 diag by using the Group sort expert.

But, I want to count the total of top 10 diag used.

GH1: Dr.Smith
GH2. Dx1 count: 80
GH2. Dx2 count: 70
GH2. Dx3 count: 70
GH2. Dx4 count: 60
GH2. Dx5 count: 55
GH2. Dx6 count: 50
GH2. Dx7 count: 45
GH2. Dx8 count: 40
GH2. Dx9 count: 30
GH2. Dx10 count: 20

Now I want the count of (80+70+70+...+20) in GH1. If I use the summary function then that counts all the diags for that DR. that are NOT in top N.

I Just want the count only Top N(10)
Any help???
 
Create a formula like this and place it in GH#2:

whileprintingrecords;
numbervar cnt := cnt + 1;
numbervar sumx;
if cnt <= 10 then
sumx := sumx + count({table.field},{table.diagnosis});

Display the result in GF1:

whileprintingrecords;
numbervar sumx;

In the Group #1 header, add a reset formula:

whileprintingrecords;
numbervar cnt;
numbervar sumx;
if not inrepeatedgroupheader then (
cnt := 0;
sumx := 0
);

-LB
 
Thanks LB.

Actually I am using total of 6 groups. First 5 groups are dynamic grouping. User can select any number of groups(1 to 5). The 6th one is the static group where the top N is displays.

Just for an example i gave 2 groups in by post. So, it is not working as i expected.
 
In what sections did you place the formulas? What results did you get?

-LB
 
I ran the report with 2 dynamic group and 1 static group(that lists top 10). Had first formula in GH6.(Where the top 10 lists).

The 2nd formula in GF1 and the 3rd in GH1.

Getting some weired count. I actually want the total in GH of the immediate prior group of GH6.(That could be GH1...GH5 as its dynamic grouping)
 
Well, no that wouldn't work. TopN works within a particular group. If you have applied topN to group #6, then the first formula goes in GH6, but the second formula must be in GF5 and the third, in GH5.

How exactly are you making your groups be dynamic? Please show the formulas you are grouping on.

-LB
 
It is not one single formual that i am using for dynamic grouping.

The first 5 groups are dynamic. If user selects only 2 the other groups(3,4,5) would be suppressed and so on.

The 6th group is static and always grouped by diagnostic code and displays top N.

for example,, If user wants to goup by location,dept then
it shows top N diag codes for each dept in each location.
GH1: Location
GH2:Dept
GH6: DIAG CODE
 
Suppressing the groups doesn't mean they have no effect unless you have set up a formula as a group that defaults to "". That was why I was asking.

Again, HOW did you set up the dynamic grouping? You must be using a parameter.

If you unsuppress all groups, and still apply the parameter for desired groups, do you see different sets of top10 codes within the unwanted groups?

I guess you might be able to add whatever criteria you are using for suppression to my formula to make the count (variable "cnt") conditional, but I would have to know what the suppression formulas for the groups in order to help you with that.

-LB
 
I have Parameter called "Grouping" which will have list of possible items(like location,dept,prov...etc). This parameter is multiple selection parameter. So, User can select the order the items to be grouped. If the user selects location and dept then it would grouped by location and dept. for other grouping "NONE" would be passed. So, when the group has "NONE" it would be suppressed. This is how my grouping and suppress formula works.
So, even if i unsupress all the groups the top N would not change.
 
But what are the fields/formulas you are inserting the groups on? You seem to be implying that the inner suppressed groups have no impact, and I can't tell whether they do or not, since I don't know exactly what you are grouping on.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top