Link to home
Start Free TrialLog in
Avatar of Becky Edwards
Becky EdwardsFlag for United States of America

asked on

CRYSTAL REPORTS Calculate a unique id using acct#, DOS and ChargeTotal

I am trying to get stats for our physicians for the month.  These are clinic visits where the patient ID doesn't change from one visit to the next.  So, I created a unique ID to count patient visits using their account ID and the month, day and year of service.  That way it is different for every month, day and year.  However, I also only want patient's whose total charges for the service date are > 0.  Otherwise it will count dates where charges were entered and backed out.
So currently my unique id is this:                (patient id plus month plus day plus year)
I want it to also say "where "sum of price" > 0.  When I use the word "where" or "when" it gives me an error.  Anyone know what the crystal syntax would be for this?
SOLUTION
Avatar of peter57r
peter57r
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Becky Edwards

ASKER

I can get it to just "display" the ones who totals <> 0, but the count in the physician's group, that counts the unique id's, is still counting the ones that total zero, even though they are not displayed.
I am grouping on service date, but have the unique id placed in that group and the formula counts unique id's.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
James:  Exactly.  I need to use a formula to count the patients, because excluding the patients with zero charges doesn't eliminate them from my count.  I need a formula that excludes them.  Any ideas?  So far my formula to "count" the patients is this:  
 (patient id plus month plus day plus year)
 
 I want it to also say "where "sum of price" > 0.  When I use the word "where" or "when" it gives me an error.  Do you know what the crystal syntax would be for this?

mimcc:     Are you counting with formulas or summary functions?
    I  am not sure I would know how to count with a summary function.  I created a unique id and put it in the Group Section where the patient resides.  It is the service date Group.
So in every service date group, there is a unique id that combines the service date and the patient id.  That is what I am counting, to get every patient visit.
 
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Mimcc:
Yes, I did right-click the field and then did Insert-Summary.  What other way is there to do it?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I have questions:  Your suggestion with my question is below...
You could try this id
In the report header
Add a formula  
 [where? in the section expert, on the formula button for suppress? If yes, I tried that and got an error of "The formula result must be a boolean".  I am not sure if I was supposed to change the word PatientCount to something, but If I am what would it be?  I am sorry to be so dense.]

WhilePrintingRecords;
Global NumberVar PatientCount := 0;
''

In the group header
Add a formula
WhilePrintingRecords;
+Global NumberVar PatientCount;
If Sum({PriceField}),{GroupField}) > 0 then
    PatientCount := PatientCount + 1;
''

In the report footer
WhilePrintingRecords;
Global NumberVar PatientCount;
PatientCount


SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok I learned something.  However, it looks just like a running total to me.  I have created a pdf of the report so you can see what is happening.  The first doctor has a sum of 3 patients, which is correct, only because there were no days with zero dollars.  Your formula computes to a 1, which just counts the patient once.  That is not what I want.  I want to count every patient every day UNLESS there are zero dollars.
The next doctor shows 254 patients.  However, it is counting those patient visits where there were zero charges.  Don't want that.  Your number (to the right) shows a zero where there are zero dollars, but is only counting the patients once, which is why it shows 5 instead of 254, I guess.
What am I doing wrong?
Sorry I forgot to add document.
Crystal-Reports---Clinic-Visits-.pdf
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
OK I kind of get what you are saying.  If I can figure out what groups to put the formula in - it should count just the ones I want.  
In the meantime, I would send this if I could figure out how.  Crystal won't let me save it in any other format, and the only other option is to export it, but then it isn't a Crystal report anymore.
Any ideas?
OK - Here is a pdf with the correct running totals.  I figured out where to place them, thanks James and mimcc for your assistance.
Now if I could just figure out how to get them into the cross-tab at the bottom that would be great.  I have attached a pdf of the results using running totals, and the results using a unique id.  You will see that Doctor #2 in the cross-tab has patients overstated by 14, due to the zero dollar days.  
So yes, the running total is more accurate, but if I want to do this for an entire 12 months and reflect it in columns, don't I have to use a crosstab?

Crystal-Reports---Clinic-Visits-.pdf
Thank you so much for your assistance!!!!!  You are a wonderful resource.
Avatar of Mike McCracken
Mike McCracken

You could build it manually using formulas.  It is a bit of a pain to do it that way.

The formulas you are using won't work with a cross tab since it uses all the data.

mlmcc
> Crystal won't let me save it in any other format, and the
 > only other option is to export it, but then it isn't a Crystal
 > report anymore.

 FYI:
 You don't save the report in a different format.  You just take the existing report file (which ends in RPT) and change the extension on the file name (rename the file) from RPT to TXT (for example) and u/l the file under the new name.  For example, if your report was named Crystal-Reports---Clinic-Visits-.rpt, you could change the name to Crystal-Reports---Clinic-Visits-.txt and then u/l the file under that name.  After you u/l'ed the file, you would change the .txt in your file name back to .rpt .  Or, if you want to be extra careful, you could make a copy of the RPT file and change the extension on the copy to TXT and u/l that copy (rather than changing the name of the original file).  If you have Windows set up to not show the extension on known file types, which I think is the default, then you probably don't see the .rpt at the end of the filename, which might be part of the problem.

 Another way to change the extension is to have the report open in CR, go to File > "Save as" and where you put in the file name, manually type .txt at the end.  I just tried that here and it worked, creating a copy of the report with .txt at the end of the name instead of .rpt, but it might depend on your Windows settings.  If that works, then u/l the copy you saved with .txt at the end of the name.


 As for the cross-tab:

 Where is the middle formula (the one that adds 1 to PatientCount) located now?  Is it in a detail section or a group header/footer?  If it's in a detail section, then I can think of something that might work.  If it's in a group header/footer, then I don't know.

 James
oK - the running totals work but they count the doctors also.  What I need is a count of patients by doctor, and a count of patients by total clinic.  Attached is the report with a .txt format.  Please rename it to .rpt for it to become a crystal report.
Thanks!

Copy-of-Clinic-Visits-by-Month-g.txt
> ... but they count the doctors also.

 If I'm following what you're saying, the total "counts the doctors" because the PatientCountGroup formula simply adds 1 to the count every time it's evaluated.  You included the formula in the doctor group header, so it adds 1 for each doctor.

 If you want to see a count for each doctor that's based on that formula, would it be OK to put the count in a group footer for the doctor, rather than the group header?  I don't think that you're going to be able to use CR's built-in summary functions to get a count based on that "sum > 0" test.  I don't think you can use Sum () on a formula that uses Sum ().  That means that you won't have the count for a doctor until the report has "printed" all of the records for that doctor.  Putting the count in the group footer would be the easiest way to handle that.


 I also have a general question about your counts.  When you say that you want a "count of patients", do you want a count of the patients that had a visit on any date that totalled over 0, or a count of the dates that patients had a total over 0?  For example, if the same patient visited on 4 days and the total for 3 of those days was over 0, does that count as 1 patient, or 3 days?  The formula that you have now is counting each date separately, so if the same patient has 3 dates that total over 0, that formula adds 3 to the count.

 James

 PS:
 I noticed that in the report you posted, you had "Doctor" in GH2, and not the actual group name.  If that was an attempt to conceal confidential information, it's only partially successful.  If I drag the group field onto the report, I can see the names.  It's included in the saved data in the report, since the report groups on that field.  You weren't displaying it, but it's there.

 If you weren't actually trying to hide that info, then I guess there's no problem.  I just wanted to mention it.

RE:  If you want to see a count for each doctor that's based on that formula, would it be OK to put the count in a group footer for the doctor, rather than the group header?
 Response:  I tried putting the count in the group footer for the doctor, rather than the header.  Then it just counts the doctor in the footer rather than the header.  I dont want it to count the doctor at all, just the patients.
 
RE:  I don't think that you're going to be able to use CR's built-in summary functions to get a count based on that "sum > 0" test.  I don't think you can use Sum () on a formula that uses Sum ().  That means that you won't have the count for a doctor until the report has "printed" all of the records for that doctor.  Putting the count in the group footer would be the easiest way to handle that.  
Response: I really dont understand what you were trying to say here.  I dont think putting the count in the group footer works, because I tried it and it counts the doctor and keeps on going to the end of the report.
 
RE:  I also have a general question about your counts.  When you say that you want a "count of patients", do you want a count of the patients that had a visit on any date that totalled over 0, or a count of the dates that patients had a total over 0?  For example, if the same patient visited on 4 days and the total for 3 of those days was over 0, does that count as 1 patient, or 3 days?  The formula that you have now is counting each date separately, so if the same patient has 3 dates that total over 0, that formula adds 3 to the count.
 
Response: Your last sentence, that is exactly what I want.  I need a count of the dates that a patient had a total over 0.  I need each date counted separately, for each patient.  So one patient came in one day, charges >0, = 1.  One patient came in 3 days, all three days > 0 each day, so = 3.  Total is 4 visits.
 
Thanks for the PS.  The confidential info is the pts name, thats all.  
Why isn't there a way to write a formula that says "Count {patientid+service date} where {sum of price} > 0? "  {PatientID+servicedate} is a formula that creates a unique id for that patient on that day.
> I tried putting the count in the group footer for the doctor,
 > rather than the header.  Then it just counts the doctor in
 > the footer rather than the header.

 Sorry for the confusion.  I didn't intend to put that same formula in the footer.  I planned to do something else.  But before I got into it, I wanted to see if it was OK to have the count in the group footer.  I don't think you're going to be able to get the count for the doctor in the group header (unless you want to use a subreport).


 > I really don't understand what you were trying to say here.
 > I don't think putting the count in the group footer works,
 > because I tried it and it counts the doctor and keeps on
 > going to the end of the report.

 Sorry (again :-).  When I talked about putting the count in the footer, I wasn't referring to your PatientCountGroup formula, but just "the count" (however it's produced).  I was just saying that the count for the doctor would probably have to be shown in the footer, rather than the header.

 
 > I need a count of the dates that a patient had a total over 0.

 OK.  Good.  That's what your current formula is counting.  It just suddenly occurred to me that you might want to just count each patient once.


 > Why isn't there a way to write a formula that says
 > "Count {patientid+service date} where {sum of price} > 0? "

 I think the basic problem with that is that summaries (Sum, Count, etc.) are done in a certain pass through the report data and in this case you're trying to do two different summaries at the same time - Sum of price for one group and then a count for another group, based on the results of the sum.  The concept of what you're trying to do may seem simple enough to you, but I just don't think it fits the way CR does things very well.

 Anyway ...

 I've got some changes for you to try.  They seem to work here.  The basic idea is to use two different variables, one for the doctor count and one for the report (clinic) count.  And you'll use a separate formula to output the doctor count.  You were using PatientCountGroup to output the doctor count, but it also adds 1 to the count.  So, we'll use a different formula that just outputs the count, without changing it.

 Change the PatientCount0 formula to the following:

WhilePrintingRecords;
Global NumberVar PatientCountDoctor := 0;
Global NumberVar PatientCountTotal := 0;

""


 PatientCountDoctor and PatientCountTotal replace the old PatientCount variable.  The "" at the end is simply so that the formula doesn't produce any output on the report.  Without that, you get a 0 on the report, unless you suppress the field/section.

 Create a new formula named PatientCountDoctor0.  It will be used to reset the doctor count for each new doctor.  Put this formula in the doctor group header (GH2).

WhilePrintingRecords;
Global NumberVar PatientCountDoctor;
if not InRepeatedGroupHeader then
    PatientCountDoctor := 0;
""


 The "not InRepeatedGroupHeader" is because you have the group header repeated on each page.  Without that check, the formula would reset the doctor count at the top of each new page.

 Change PatientCountGroup to the following:

WhilePrintingRecords;
Global NumberVar PatientCountDoctor;
Global NumberVar PatientCountTotal;
If Sum({BIMWDCP.DCEPRC}, {@SvcDate}) > 0 then
(
    PatientCountTotal := PatientCountTotal + 1;
    PatientCountDoctor := PatientCountDoctor + 1;
);


 That now increments both the doctor count and the new total (clinic) count.  It increments the doctor count last, so if you let the formula show on the report, you'll see the doctor count, same as before.  If you don't want to see the count, you can add "" at the end (like the earlier formulas).

 The PatientCountGroup formula should be _only_ in GH5 (the @SvcDate group header), and nowhere else.


 FWIW, I renamed the PatientCountFooter formula to PatientCountTotal, just because Footer could mean group or report footer (and the new name matches the name of the new PatientCountTotal variable).  You can keep the old formula name if you like.  But you need to change the formula to use the new variable name:

WhilePrintingRecords;
Global NumberVar PatientCountTotal;
PatientCountTotal


 Create a new formula named PatientCountDoctor and put it in the doctor footer (GF2):

WhilePrintingRecords;
Global NumberVar PatientCountDoctor;
PatientCountDoctor


 I think that should do it.  To recap:

 PatientCount0

 In the report header.
 Declares two variables, PatientCountDoctor and PatientCountTotal, and sets them to 0.


 PatientCountDoctor0

 In the doctor group header (GH2).
 Resets the doctor count, PatientCountDoctor, for each new doctor.


 PatientCountGroup

 In the @SvcDate group header (GH5), and _nowhere_ else.
 Increments both the doctor and total (clinic) counts.


 PatientCountFooter (formerly PatientCountTotal)

 In the report footer.
 Outputs the total (clinic) count.


 PatientCountDoctor

 In the doctor footer (GF2).
 Outputs the doctor count.



 Do you want the doctor counts in the cross-tab too?  That's trickier, but I've come up with something that seems to work.  It's a bit off the wall and I make no guarantees, but it does seem to work with the data saved in the report you posted.

 James
OK, when describing the changes to the PatientCountGroup formula, I said:

 > That now increments both the doctor count and the new total (clinic) count.
 > It increments the doctor count last, so if you let the formula show on the
 > report, you'll see the doctor count, same as before.  If you don't want to
 > see the count, you can add "" at the end (like the earlier formulas).

 In case this wasn't clear, what I meant by "you'll see the doctor count", was the incrementing count (1, 2, 3, 4, etc.) that you've been getting from this formula every time it adds 1, _not_ the final count for each doctor.  The new PatientCountDoctor formula will output the final count for each doctor in the doctor group footer (GF2).  PatientCountGroup, if you let it show, will show the count as it's being accumulated.  I just wanted to make it clear that I wasn't talking about the final count for the doctor there.

 James
James:  I can get everything just right except the doctor count.  I am missing something here.  Could you look at this one and see?  You have to rename it to .rpt to get it to work.
Clinic-Visits-by-Month-TEST.txt
You missed one formula.

 Create a new formula named PatientCountDoctor and put it in the doctor footer (GF2):

WhilePrintingRecords;
Global NumberVar PatientCountDoctor;
PatientCountDoctor



 You have PatientCountDoctor0 in the doctor group header (GH2), and that's correct, but all that does is reset the count to 0 for each new doctor.  The PatientCountDoctor formula above is the one that shows the count for each doctor, and it has to go in the footer (GF2).

 James
OMG It works.  Thank you Thank you Thank you.  
Now I need a crosstab with these doctors in it.  Shall I ask the question or do we continue with this discussion?
I kind of hate to leave all this discussion behind, but you should probably start a new question, partly because a cross-tab wasn't specifically part of your original question, but also largely just because this question has already been closed for a week.  You can use the "ask a related question" link right above where you type in your comment and it will start a new question, with a link pointing to this one for reference.

 Whether you start a new question or we continue here, post exactly what you want in the cross-tab.  In one of the reports you posted earlier, you had what I think was a count of each patient visit.  Do you want that count _and_ the "> 0" count, or just the "> 0" count, or something else?  FWIW, I think I've come up with a way to get the "> 0" count in a cross-tab.  It's kind of off the wall, but it seems to work.  So, hopefully, the cross-tab part won't be too difficult.

 James
Oh, and you're welcome.  :-)

 James