Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Subtracting data from other records Post Reply Post New Topic
Author Message
PrezWeezy
Newbie
Newbie


Joined: 10 May 2011
Online Status: Offline
Posts: 2
Quote PrezWeezy Replybullet Topic: Subtracting data from other records
     Posted: 10 May 2011 at 1:44pm
Hello all, and thanks in advance for any help you can give.
 
I have a SQL database I'm running this report from, and I have a problem I haven't run into yet:
When time is entered into the database there is a Job number, the amount of time being entered, and the type of the time (regular time, overtime, etc.)
I have a summary field which takes each employee and adds up the regular time, and a second summary adding up the overtime.
The catch is that when a mistake is made, they create a NEW job number and append a -01, or -02 if they make two mistakes.  So now instead of the job number being 12345, it is 12345-01, or 12345-02.  I sometimes even have 12345, 12345-01, 12345-02, and 12345-03.  What I need to do is only summarize the "latest" version of the job number.
 
My original thought was to take the full summary and subtract from it job numbers which had been superseded, but I haven't been able to figure out how to do that.  Anyone have any ideas as to how to make this work?  The original and the corrections are rarely sequential, ie there are usually several records in between them, and a random number at that.  I'm really a little lost on how to write a formula to deal with that.  Any help or pointer in the right direction would be very appreciated.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 11 May 2011 at 3:14am
if the job numbers are as displayed, you could create a formula like:
local stringvar aJob := {table.field};
local numbervar aDash := instr({table.field}, "-");
 
if aDash = 0 then
  aJob
else
  left(aJob, aDash - 1)
 
 
 
you can group on this formula, which will put all the jobs into one group.
 
Then you can have another group inside of this one that is by {table.field} in DESCENDING order, so the latest revision is the first record.
 
Since I use shared variables, while other might use running totals, I will explain what I would do...In the 'super' group header, I would set a flag, and initialize the variables to 0.  In the footer of the 'normal' group, I would check the flag, if it is the first group, I would set the flag and ADD the sum of the group, if it is not the first group I would SUBTRACT the sum of the group.  In the footer of the 'super' group, I would then display the value of the variable:
 
shared numbervar theTotal;
shared booleanvar firstFlag;
 
if firstFlag then (
  firstFlag = false;
  theTotal := theTotal + SUM({table.fieldToSum}, {table.fieldJobNumber});
else
  theTotal := theTotal - SUM({table.fieldToSum}, {table.fieldJobNumber});
);
""  //hides the output
 
HTH
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 11 May 2011 at 4:03am
For a running total version i would group on the job formula like lockwelles to get all the jobs togther, strip the job number of the end and sort desc by that.
 create 2 rts
name = regular time
field to summarize = regular time field
type = sum
evalauate on change of group (select the job group)
reset= never
 
if you need it per employee add a group at the employee level and change the reset to on change of group (employee group)
 
repeat for OT usingt hat as the field to summarize
IP IP Logged
PrezWeezy
Newbie
Newbie


Joined: 10 May 2011
Online Status: Offline
Posts: 2
Quote PrezWeezy Replybullet Posted: 23 Jun 2011 at 9:20am
Sorry this has taken so long to get back, this job got put on the back burner for a while.  And thank you for your replies, but I had another question on it:
 
Is there not a way to grab the row number and subtract that jobs hours from the total?
So I could do something like the following:
 
local var currentJob = {job_id};
local var prevJob;
 
 
if right(currentJob, 3, 1) = "-"
then prevJob = currentJob - 1;
*get hours from prevJob row and subtract from total*
else "total" += currentJob
 
I know that my syntax is pretty terrible, but it was just a thought at a way to solve the problem.  I am partially asking because I'm somewhat new to Crystal and so I want to know what is possible.
 
Thanks again, looking forward to your replies.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 27 Jun 2011 at 3:06am
sure, depending on if the rows are directly next to each other, then you can use the Previous() function.
 
If there is some space, you can store the 'Previous' value in a shared variable just like the job_id.
 
HTH
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