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!

Calculating difference between records vice groups

Status
Not open for further replies.

pharmIT

Technical User
Apr 29, 2011
1
US
Crystal 8.5 User

I have a subreport that contains various lab values. I only want the most recent lab to be displayed, so I have them grouped by labcode with fields in the group header and the details and group footer suppressed.
I have hit a wall trying to now display the difference between the latest lab for a specific labcode and the previous value. With the formula field in the group, the report returns the difference between groups; ie. 'BUN' - 'CREAT' vice 'BUN' - previous 'BUN'.

Can anyone offer a suggestion on how to fix this? I have included the code I am trying to use. I think it would work within the Detail section, but then I will get more than the latest lab displaying. Thanks in advance!

if {VISITLAB.CODE} = 'BUN' then
{VISITLAB.LABVALUE} - previous({VISITLAB.LABVALUE})
else
if {VISITLAB.CODE} = 'CREAT' then
{VISITLAB.LABVALUE} - previous({VISITLAB.LABVALUE})
else
if {VISITLAB.CODE} = 'HCS_CRCL' then
{VISITLAB.LABVALUE} - previous({VISITLAB.LABVALUE})
else
if {VISITLAB.CODE} = 'WBC' then
{VISITLAB.LABVALUE} - previous({VISITLAB.LABVALUE})
 
First of all your formula should have been using "next" if you are placing it in the group header (with records sorted by descending date) and you don't need the if then because you have already grouped on lab code--but it still won't work with suppressed records.

Another approach would be to add the same table again, linking on lab code and on lab date, using a > link for the lab date FROM the original table TO the visitlab_1 table. Then you can use a formula like this in the group header:

{visitlab.labvalue}-{visitlab_1.labvalue}

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top