Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Subtracting the First and Last Fields in a Group Post Reply Post New Topic
Author Message
PatrickBock
Newbie
Newbie
Avatar

Joined: 13 Nov 2008
Online Status: Offline
Posts: 2
Quote PatrickBock Replybullet Topic: Subtracting the First and Last Fields in a Group
     Posted: 13 Nov 2008 at 10:47am
Hello.  This one is stumping me.  I've created a report that pulls student's scores on tests. 

Test Date   Score1   Score 2
1/1/08        550        550
1/3/08        560       560
1/5/08        590        590

I need the report to give me the difference from first test to last test for both Score1 and Score2. 

A few caveats:  Not every student has taken three tests.  Many take more than three.  I need to subtract the oldest test Score1 from the newest test Score1, the only condition being that the student has taken more than 2 tests.

The score improvement must also be later computed as part of an average.

Many thanks for any help you can provide.
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 13 Nov 2008 at 5:05pm
Two ideas come to me. I would use the Min() and Max() functions to get the first and last date and then in a formula check if the current date equals either one. If so, save it to a global variable and then do the difference in the group footer.

Secondly, In the group header section store the current score to a global variable and then in the group footer subtract that from the current value. This effectively lets you subtrace the first record from the second record as long as they are sorted by date. This is probably the best method of the two.
 
My book, Crystal Reports Encyclopedia, has many tips and tricks for advanced report formatting. You can find out more about my books at Amazon.com or reading the Crystal Reports eBooks online.
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
PatrickBock
Newbie
Newbie
Avatar

Joined: 13 Nov 2008
Online Status: Offline
Posts: 2
Quote PatrickBock Replybullet Posted: 14 Nov 2008 at 6:51am
Thank you so much for your reply.  I actually have already ordered your book -- can't wait for it to come.  This global variable concept is definitely new to me.  

I figured out the min() max() analysis yesterday, and went in a slightly different direction.  I created a formula to identify the score as first, last, or neither:
if {tbResult.dateEntered} = Maximum ({tbResult.dateEntered},{tbResult.custID}) then "Last" else
if {tbResult.dateEntered} = Minimum ({tbResult.dateEntered},{tbResult.custID}) then "First" else
"Neither"

I then created another formula to return the first score * (-1) for the min date:
if {@First or Last} = "First" then {tbResult.score1}*-1 else
if {@First or Last} = "Last" then {tbResult.score1} else 0

Those two formulas did what I wanted.  When I tried to  then add the two scores, however, I received an error message stating that Crystal couldn't summarize with the sum() function. 

If I pursue your idea, will this global variable be local enough that it will change on each group (i.e., each student)?  The report will contain information on several hundred students, so the variable is going to have to change each time.

Thanks for your time!

EDIT
I'm definitely on board with your second idea, but I don't know how to assign a Global Variable to the first record.  I declare and assign the variable in the group header.  However, when I try using a formula in the group footer like: FirstScore //the name of the global variable // -  {tbResult.score1}, the formula treats FirstScore as the final record (i.e. the one closest to the group footer when the tests are sorted by date.

Can you give me an example of the exact syntax I'm going to need to use?  Again, thanks for your help.


Edited by PatrickBock - 14 Nov 2008 at 2:57pm
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