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!

Top 3 of Several NumberVars

Status
Not open for further replies.

ProfessorSnail

Technical User
Oct 11, 2010
10
GB
Can I use a formula to evaluate a NumberVar against a series of other NumberVars to determine whether it is within the top three?

I have 12 NumberVars which are used to count the number of records attributed to a particular injury type and display a percentage on a body parts injury diagram. I would like to determine the top three injury types so that I can suppress certain objects e.g.

If "NumberVar Head" is in the top 3 out of "NumberVar UpperBody", "NumberVar Back"...etc then true else false.

???

Thanks in advance for any help
 
Top 3 of what? The entire report. Please explain your group structure, where your variable formulas are located, and also show their content. When you refer to a diagram, do you mean a chart or literally a visual image? In what report section is this located?

-LB
 
The report is currently structured as follows:

Group 1: Injury Extent ({TW_V_INJURED_BODY_PART_S_INJURY_EXTENT.name} either "Main" or "Additional")
Group 2: Body Part (Formula, see below)

The "Body Part" grouping is a formula field which groups a field called {TW_V_INJURED_BODY_PART_S_INJURED_BODY_PART.name}. It’s simply an IF statement. Here's the first line:

if {TW_V_INJURED_BODY_PART_S_INJURED_BODY_PART.name} in ["Head", "Forehead"]
then "Head"
else
if ... //and so on of all the body part categories

The report is sorted by a count of group 2 i.e. the highest number of injuries attributed to a body part group is at the top.

My variables are calculated in the details section and then displayed in the Group 1 footer as a percentage of the records. This is also where the diagram (Image) is displayed. Here’s a snippet of the variable calculation formula:

WhilePrintingRecords;

Shared numberVar Head;
Shared numberVar Face;
// several more variables after this

if {TW_V_INJURED_BODY_PART_S_INJURED_BODY_PART.name} in ["Head", "Forehead"]
then Head := Head+1;
if {TW_V_INJURED_BODY_PART_S_INJURED_BODY_PART.name} in ["Eye", "Ear", "Nose", "Cheek", "Jaw", "Mouth", "Teeth", "Tongue"]
then Face := Face+1;
// continues for other variables

Here’s an example of how the “Head” variable is displayed in the Group 1 footer to give a percentage:

WhilePrintingRecords;

Shared numberVar Head;
Head/Count ({PR.id}, {TW_V_INJURED_BODY_PART_S_INJURY_EXTENT.name})*100

This all works fine and gives me a nice percentage break down of where injuries are occurring. I now want to take the report a step further and display a different image depending on how the percentage is ranked i.e. the top three will appear red, the next three amber, and all the others Green. I’ve over laid the three images (red, amber, green) for each body part group and want to suppress them based on the ranking.

Hope I’ve answered all your questions?

Thanks in advance for all your support.


 
I don't understand why you are using variables. You should be able to right click on some identifier and insert a count at the Group #2 level. If you want it expressed in percentage, then choose that option when you insert the count.

What do the images look like? I'm not clear on where the images are located--it sounds like they are in Group #1 footer, but then you seem to be talking about suppressing some Group #2 results and coloring other Group #2 sections--so I am still confused.

-LB

 
I'm using variables because I want to display the results in the group 1 footer where the image is displayed.

The image is a human figure broken down into body part sections. The report should identify the top three parts of the body which are injured and therefore I would like to suppress an overlapped image to show a different colour underneath.

I'm sorry if I have not explained the structure of the report very well. The records are displayed in text form in the details section. I then have a group 1 which is the injury extent (either "Main" or "Addition" creating two parts to the report) and then a group 2 of the body part injured. However, the image resides in the group 1 footer because I want two images on the report (One for the main injuries and one for the additional).

The problem I have is identifying which variables are in the top 3, and the next 3, and so on. I could use a separate formula for each body part which displays a 1 or 0 and then sum in group 1 if this makes the solution easier?

I'm really stuck and may need to think of an alternative like suppressing based on the percentage value rather than the rank.
 
If I'm following this correctly, and your Group #2 is based on a formula that breaks out into the same categories as your variables, then you should be able to insert a count at the group #2 level, and then do a group sort so that the highest count appears first. Then you could create a formula that establishes an array, like this:

//{@accum} to be placed in a group #2 section:
whileprintingrecords;
stringvar array top3;
stringvar array mid3;
numbervar i := i + 1;
numbervar j;
numbervar k;
if i in 1 to 3 then (
j := j + 1;
redim preserve top3[j];
top3[j] := {@bodypartname}
);
if i in 4 to 6 then (
k := k + 1;
redim preserve mid3[k];
mid3[k] := {@bodypartname}
);

Add a reset formula to group header #1:
whileprintingrecords;
stringvar array top3 := "";
stringvar array mid3 := "";
numbervar i := 0;
numbervar j := 0;
numbervar k := 0;

Then in group footer #1, you can check for matches by using formulas like this in the color formatting area:

whileprintingrecords;
stringvar array top3;
stringvar array mid3;
if "Face" in top3 then
crRed else
crNoColor

Or use the arrays for conditional suppression formulas.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top