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

Multivalue Field Grouping (Arrays??)

Status
Not open for further replies.

gpincomb

Programmer
Feb 11, 2004
12
0
0
US
I have Crystal Reports 8.5

I am building a report over a Doctor Database in Lotus Notes. Each Doctor has a Department field which contains only one department. Each Doctor has a Specialty field that is free form and can contain more than one specialty. i.e.

Doctor Name Department Specialty
Dr. Aabba Anesthesia Anesthesiology
Dr. Babba Anesthesia Anesthesiology,Pain Mngmt.
Dr. Cabba Family Pract. Familty Pract.
Dr. Dabba Family Pract. Geriatrics,Family Pract.

I am trying to build a drill down report that shows the following:

Anesthesia 3
Anesthesiology 2
Dr. Aabba
Dr. Babba
Pain Mngmt 1
Dr. Babba
Family Pract. 3
Family Pract. 2
Dr. Cabba
Dr. Dabba
Geriatrics 1
Dr. Dabba
TOTALS 6

Yes, I know that this means that some of my Doctors get counted more than once but this is the way my users want it. I am trying to avoid using Crystal SQL Designer and Crystal Dictionaries as this report will be going out to Crystal Enterprise. I also have access to Crystal 9.0 through a collegue, if using this would be easier. I have figured out how to get all of my specialties into one large array, through the use of a subreport, but I am not sure if this is the way I should go or not. Any help is greatly appreciated. Thanks.
 
This is a much better description of your problem than your earlier post. I think you could do this by grouping on department and then on specialty. Suppress the specialty group header, and then, since your earlier post showed up to three specialties per field, create three formulas:

//{@Spec1}:
split({table.specialty},",")[1]

//{@Spec2}:
if ubound(split({table.specialty},",")) > 1 then
split({table.specialty},",")[2]

//{@Spec3}:
if ubound(split({table.specialty},",")) > 2 then
split({table.specialty},",")[3]

Then create three subreports.

First insert a subreport called "Spec1", and add {table.drname} to the detail section. In the subreport, create a formula {@Spec1}:

split({table.specialty},",")[1]

Insert a group on this formula, and then suppress all sections except the group header and the details section. Link the subreport to the main report using the corresponding formula {@Spec1} in each. Place the subreport in group (specialty} footer 2_a.

Repeat for the other two subreports, using {@Spec2} and {@Spec3} for the links, and placing each in its own group footer 2 section.

In subreports "Spec2" and "Spec3," suppress the group header and details section with a formula like:

{@Spec2} = ""

and format these same sections with "Suppress Blank Section." In the design window of the main report resize these to be as small as possible.

I would also add {table.drname} as a sort field in each subreport. In the main report, add {@Spec1}, {@Spec2}, {@Spec3}, and {table.drname} to report->sort order.

I think that should do it.

-LB
 
First of all thanks, a lot closer. Still have some issues though.

Had to tweak it a bit because there are some specialties like Cardiology that are in multiple departments. For example:

Doctor Name Department Specialty
Dr. Apple Family Pract. Cardiology
Dr. Bapple Pediatrics Cardiology

At first both doctors were showing up in both departments under Cardiology, I added Department to my subreport link and this fixed the problem.

Additional issues:

Data Example:
Doctor Name Department Specialty
Dr. Ache Anesthesia Anesthesiology
Dr. Bache Anesthesia Anesthesiology,Pain Mngmt.

Results:
Anesthesia
Anesthesiology (From Anesthesiology)
Dr. Ache
Dr. Bache
Anesthesiology (From Anesthesiology,Pain Mngmt.)
Dr. Ache
Dr. Bache
Pain Mngmt.
Dr. Bache

I need the second set of Anesthesiology suppressed. Also as I stated my users would like this to be a drill down report. I've been able to set up the department to drill down to the subreport Specialty, but it also pulls up the doctor names, when it shows the specialty. I need the Dr. Names hidden until the specialty is drilled upon. If I hide the Dr. Names in the subreport then they are never seen, even when I drill down on the Specialty.
 
Did you remember to format the group header and detail sections within the {@Spec2} and {@Spec3} subreports to suppress with the condition:

{@Spec2} = "" //or {@Spec3}

Can you verify which subreport the duplicating results are coming from {@Spec1} or {@Spec2}?

On the drilldown issue--if you hide the details of the subreport, the users can drill down on the specialty in the main report, which will take them to the same specialty in the subreport, and then they would have to drilldown again to see the doctors' names. I cannot replicate the problem you are having with drilling down in the subreport.

If you want more control over drilldown (although you don't seem to need this feature for your current purpose), CR 9.0 has a function "DrillDownGroupLevel" that you can use to conditionally suppress different headers based on the drill down level.

-LB
 
Closer, but a couple of issues left.

I did remember to Group and Suppress as specified, but was still getting the problem. But having you mention the suppression got me thinking and this is what I came up with:

In my subreport "Spec1" I created the following:
//{@Reset}
stringVar HldSpec1 := "";
I placed this in my report header.

//{@DspSpec1}
whileprintingrecords;
shared stringVar DspSpec1;
DspSpec1 := {@Spec1};
DspSpec1;
I placed this in my Group Header #1

//{@ChkSpec1}
evaluateafter({@DspSpec1});
shared stringVar HldSpec1;
shared stringVar DspSpec1;
shared numberVar Flag1;
If HldSpec1 = DspSpec1
Then Flag1 := 1
Else Flag1 := 0;
Flag1;
I placed this in my Details

//{@HldSpec1}
evaluateafter({@ChkSpec1});
shared stringVar HldSpec1;
shared stringVar DspSpec1;
HldSpec1 := DspSpec1;
HldSpec1;
I placed this in my Group Footer #1

I then suppressed the Group Header, Footer, and Details sections based on the following condition:
evaluateafter({@ChkSpec1});
shared numberVar Flag1;

Flag1 = 1;

I did this for my subsequent subreports as well, but in the subsequent subreports you must do a record selection based on something like {@Spec2} <> &quot;&quot;

This eliminated my duplicate sections within each subreport, but it does throw off my spacing a little in the Main report. Even though I have Suppress Blank Sections in my subreports and on my subreports, the sections removed by the above method leave a minimal blank section. Also, still having an issue of duplicate sections when combining the two different subreports, for example:

Name Department Specialty
Dr. Ack Pediatrics Gastroenterology,Pediatrics
Dr. Back Pediatrics Neonatology,Pediatrics
Dr. Cack Pediatrics Pediatrics
Dr. Dack Pediatrics Pediatrics,Critical Care

Results:

Pediatrics (Department)
Critical Care (This is Correct)
Dr. Dack (This is Correct)
Gastroenterology (This is correct)
Dr. Ack (This is correct)
Neonatology (This is correct)
Dr. Back (This is correct)
Pediatrics
Dr. Cack
Dr. Dack
Pediatrics
Dr. Ack
Dr. Back

Being that these are coming from two different subreport can they be combined into one group?
 
To put things in perspective, the problem is in how the data is stored. This is not a normailzed structure, hence the kludge fix.

An alternative to working around this problem in local code everytime you might want to work with this data would be to create a View to properly normalize it on the server (this is database dependent which you didn't share).

There are a few means by which you might do this, but the easiest might be a simple Union wherein the SQL is almost identical for each Union select, the only difference being a case or decode to test for each condition and return one row for each Specialty.

You can also manually create a Union with Crystal using Database->Show SQL Query

Then this report is a snap, and if you create it on the database as a View, going forward you'll have a normalized structure.

BTW, see to it that your dba/database architect becomes a permanent patient of Dr. Babba's Pain Management practice for designing it this way.

-k
 
I have to agree with SV--we're going through all kinds of pretzel-bending (that seems like the right image) to make this work, and it is not going to work perfectly. For the repeating heading where &quot;Pediatrics&quot; is appearing in Spec1 and then again in Spec2, you could create a shared variable in subreport Spec1 (and place it somewhere on the subreport canvas):

shared stringvar split1 := split({table.specialty},&quot;,&quot;)[1];

Then in Spec2, format the group header section with:

whileprintingrecords;
shared stringvar split1;

{@split2} = &quot;&quot; or //my original suggestion which you can (and did) alter
split1 = split({table.specialty},&quot;,&quot;)[2];

This will remove the redundant heading; however, I don't think there is a way to then make the doctors' names alphabetical since they are coming from different subreports.

-LB
 
SV, my first post did state that this is off a Lotus Notes Database, sorry if it was that understandable.

My users are not worried about the Dr. Names being in alpha order, so if we cannot have that then I can live without it.

Sorry, I showed the results in a slightly different order than actual trying to give it more clarity, and lb I tried your suggestion and got the same results which actually are:

Pediatrics (Department)
Critical Care (This is Correct)
Dr. Dack (This is Correct)
Gastroenterology (This is correct)
Dr. Ack (This is correct)
Pediatrics
Dr. Ack
Dr. Back
Neonatology (This is correct)
Dr. Back (This is correct)
Pediatrics
Dr. Cack
Dr. Dack

I thought the other order better showed what I was wanting, but I now see that it actually confused the subject a little, because as you can see the Split1 and Split2 are not one after the other and therefore cannot be compared. I agree that the data is stored in a awfully funky way, and maybe some day, I'll be able to convince our Lotus Notes Adminstrator to put the specialties into several multiple fields for each doctor, instead of one free format field separated by commas. But for now I've got to try to work with what I got. Thanks for all your help so far.
 
Your results still don't make sense if your records are in fact like the following:

Name Department Specialty
Dr. Ack Pediatrics Gastroenterology,Pediatrics
Dr. Back Pediatrics Neonatology,Pediatrics
Dr. Cack Pediatrics Pediatrics
Dr. Dack Pediatrics Pediatrics,Critical Care

Are you grouping only on department in the main report and placing the subreports in the department group footer? That wasn't my original suggestion, but seems to be the right approach with all the redundancy...

You would expect (I think):

Gastroenterology //beginning of Spec1
Ack
Neonatology
Back
Pediatrics
Cack
Dack //end of Spec1

Critical Care //beginning of Spec2
Dack
Pediatrics
Ack
Back //end of Spec2

-LB
 
I see what you're saying, about the Spec1 and Spec2 being mixed whileprinting under the current setup, because I am grouping secondly on the Entire Specialty Field. So therefore what I'm getting is:

Gastroenterology (Spec1 - Gastroenterology,Pediatrics)
Pediatrics (Spec2 - Gastroenterology,Pediatrics)
Neonatology (Spec1 - Neonatology,Pediatrics)
Pediatrics (Spec2 - Suppressed from SR Spec2 - Neonatology,Pediatrics)
Pediatrics (Spec1 - Pediatrics)
Pediatrics (Spec1 - Suppressed from SR Spec1 - Pediatrics,Critical Care)
Critical Care (Spec2 - Pediatrics,Critical Care)

So it now looks like this:
Gastroenterology
Pediatrics (Spec2)
Neonatology
Pediatrics (Spec1)
Critical Care

If I take out the grouping by the Entire Specialty Field, then I end up with only one specialty per department, and the rest are off in oblivion somewhere.
 
Still looking for a final resolution to this, does anyone have any ideas??
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top