Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Formula to find difference in from different recor Post Reply Post New Topic
Author Message
dlabrec
Newbie
Newbie


Joined: 03 Jun 2008
Location: United States
Online Status: Offline
Posts: 20
Quote dlabrec Replybullet Topic: Formula to find difference in from different recor
     Posted: 03 Jun 2008 at 7:45am
Newbie here. I have been reading and going thru the book online. This is my first post, so I apologize in advance if I am giving too much, or not enough information.

I work for a dialysis company and am trying to create a report that will calculate the change in a patient's weight from one treatment day to the next.

I currently have the report setup with parameters where the user can request a date range of information.

The tables record the patient's pre-weight and post-weight for each treatment day.

I want the formula to calculate the difference between the pre-weight of the current day and the previous treatment's post-weight.

I created this formula:
{DIALYSUM.PRE_DIAL_WEIGHT_KG} - {DIALYSUM.POST_DIAL_WEIGHT_KG}

But that is comparing the pre and post weight from the same treatment date. I want the post to be from the previous treatment. This way we can see how much weight the patient gained or lost since their last treatment.

Patients typically have 3 treatments per week, either Mon-Wed-Fri or Tue-Thur-Sat if that matters.

Any help in figuring out how to specify the post wt. be for the previous treatment would be appreciated.

Thanks,
David
IP IP Logged
saoco77
Senior Member
Senior Member


Joined: 26 Jun 2007
Online Status: Offline
Posts: 104
Quote saoco77 Replybullet Posted: 03 Jun 2008 at 10:09am
The previous function allows you to evaluate data from the previous record. Try something like this.

{DIALYSUM.PRE_DIAL_WEIGHT_KG} - previous({DIALYSUM.POST_DIAL_WEIGHT_KG})


Hope this helps.

Sarah



IP IP Logged
dlabrec
Newbie
Newbie


Joined: 03 Jun 2008
Location: United States
Online Status: Offline
Posts: 20
Quote dlabrec Replybullet Posted: 03 Jun 2008 at 10:51am
Sarah,

Thanks for your reply. You have me on the right track. I applied the "previous" function, but it is working the opposite way I want it to.

Here is an example of what I got after apply previous to the formula
{DIALYSUM.PRE_DIAL_WEIGHT_KG} - previous({DIALYSUM.POST_DIAL_WEIGHT_KG})

Date    Pre Wt     Post Wt       Wt Change
6/2/08   71.00       68.70       
5/30/08 70.80       69.05        2.10

The formula is taking the pre-weight from 5/30 and subtracting the post-weight from 6/2 giving the result of 2.10. (70.80 - 68.70 = 2.10.

Instead, I am trying to get the formula to take the pre wt from 6/2 (71.00) and subtract the post weight from 5/30 (69.05) to get the weight change on the 6/2 line to show as 1.95.

Is their a function opposite of previous, such as Next?


Edit..Update, their is a next function and that did the trick, replacing previous with next. Thanks again Sarah for your help.

Edited by dlabrec - 03 Jun 2008 at 10:52am
IP IP Logged
dlabrec
Newbie
Newbie


Joined: 03 Jun 2008
Location: United States
Online Status: Offline
Posts: 20
Quote dlabrec Replybullet Posted: 03 Jun 2008 at 12:32pm
I applied the next function and that is doing the calculation I want, but it is continuing the calculation across groups.

Is there away I can restrict the formula to distinct groups?

Here is an example:

Doe, Jane
   Date    Pre Wt     Post Wt       Wt Change
   6/2/08   71.00       68.70        1.95
   5/30/08 70.80       69.05       (23.2)

Doe, John
   Date    Pre Wt     Post Wt       Wt Change
   6/2/08   95.00       94.00        2.5
   5/30/08 93.00       92.5       

The weight change formula value for Jane Doe on 5/30 (-23.2) is being calculated by taking Jane Doe's pre weight on 5/30 (70.80) and subtracting the next record which is John Doe's post weight on 6/2 (94.00).

How can I restrict the formula so it does not look at the next group? The weight change value of the last row of each group should be blank since the calculation can't be completed.

Here is the formula I am currently using:
{DIALYSUM.PRE_DIAL_WEIGHT_KG} - next({DIALYSUM.POST_DIAL_WEIGHT_KG})

Thanks in advance for any suggestions.

David
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum