Tips and Tricks
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Tips and Tricks
Message Icon Topic: Running Total Post Reply Post New Topic
Page  of 2 Next >>
Author Message
Duward
Newbie
Newbie
Avatar

Joined: 02 Oct 2008
Location: United States
Online Status: Offline
Posts: 5
Quote Duward Replybullet Topic: Running Total
    Posted: 02 Oct 2008 at 5:47pm
I have a problem I have to do a report to show the employees weekly hours and I can't get the field to summarize. For each day I am doing this.
 
Regular hours:
If Sum({tblLaborDetail.intPayHours}) > 8 Then
    8
Else
    Sum({tblLaborDetail.intPayHours})
 
OT-1:
If Sum({tblLaborDetail.intPayHours}) > 8 And Sum({tblLaborDetail.intPayHours}) < 12 Then
    Sum({tblLaborDetail.intPayHours}) - 8
Else If Sum({tblLaborDetail.intPayHours}) > 12 Then
    4
Else
    0
 
OT-2:
If Sum({tblLaborDetail.intPayHours}) > 12 Then
    Sum({tblLaborDetail.intPayHours}) - 12
Else
    0
 
But you cannot summarize this type of formula to do a week ly total.  I have to total the Regular hours, Overtime time and a half and Overtime for double time.
 
I have tried to use basic syntax to do an if statement but it always adds the last days time.
 
Dim z As Number
Dim i As Number
Dim x As Number
x = 0
For i = Day({?DateFrom}) to Day({?DateTo}) Step 1
    If {tblLaborDetail.dteStartActivityDate} = {?DateFrom} Then
        z = Sum ({tblLaborDetail.intPayHours}, {tblLaborDetail.dteStartActivityDate}, "daily")
    ElseIf {tblLaborDetail.dteStartActivityDate} = {?DateFrom} + 1 Then
        z = Sum ({tblLaborDetail.intPayHours}, {tblLaborDetail.dteStartActivityDate}, "daily")
    ElseIf {tblLaborDetail.dteStartActivityDate} = {?DateFrom} + 2 Then
        z = Sum ({tblLaborDetail.intPayHours}, {tblLaborDetail.dteStartActivityDate}, "daily")
    ElseIf {tblLaborDetail.dteStartActivityDate} = {?DateFrom} + 3 Then
        z = Sum ({tblLaborDetail.intPayHours}, {tblLaborDetail.dteStartActivityDate}, "daily")
    ElseIf {tblLaborDetail.dteStartActivityDate} = {?DateFrom} + 4 Then
        z = Sum ({tblLaborDetail.intPayHours}, {tblLaborDetail.dteStartActivityDate}, "daily")
    ElseIf {tblLaborDetail.dteStartActivityDate} = {?DateFrom} + 5 Then
        z = Sum ({tblLaborDetail.intPayHours}, {tblLaborDetail.dteStartActivityDate}, "daily")
    ElseIf {tblLaborDetail.dteStartActivityDate} = {?DateFrom} + 6 Then
        z = Sum ({tblLaborDetail.intPayHours}, {tblLaborDetail.dteStartActivityDate}, "daily")
    End If
    If z > 8 Then
        x = x + 8
    Else
        x = x + z
    End If
Next i
formula = x
 
I am desperate I have to have this by Monday so any help is very appreciated.
IP IP Logged
rptfan
Newbie
Newbie
Avatar

Joined: 04 Oct 2008
Online Status: Offline
Posts: 13
Quote rptfan Replybullet Posted: 04 Oct 2008 at 12:06pm
Do you just want it to not displays the last days time? Use your for loop. Use the help file to learn how to use the date functions.

You want something like..

For i = Day({?DateFrom}) to (Day({?DateTo}) - 1) step 1

But, you have to convert {?DateTo} to a number, minus one day from it, and then convert it back to a date, and then use the day function. You can do it. You just have to use the date functions.
Save money deploying Crystal Reports!
Try a Crystal Reports Viewer.
Refresh data. Export and manage reports.
Easy to use. Free to try.
IP IP Logged
Duward
Newbie
Newbie
Avatar

Joined: 02 Oct 2008
Location: United States
Online Status: Offline
Posts: 5
Quote Duward Replybullet Posted: 04 Oct 2008 at 2:48pm
Thank you very much for answering my post.  As to your question no I want it to add up the whole week for each employee but it is adding the last days hours 7 times.  I am not using the date right I guess but I have been through the help file and it doesn't let you summarize by a date just a group.  I can get it to add each days many detail records (they have mutiple records because they clock in and out multiple times each day) so everything works except for the weeks total.  I can get a week total but not broken done by regular hours, ot1, and ot2.  I should have written this in VB where I can use sql for each calculation instead of trying crystal.  It gets very frustrating every time I go to save and get an error message because crystal's basic doesn't work like I am used to.  If only crystal would let you do a running total on a formula it would all work.  I am going to add the field to the header table and try and summarize them.  Once again thanks for your help.


Edited by Duward - 04 Oct 2008 at 2:50pm
IP IP Logged
rptfan
Newbie
Newbie
Avatar

Joined: 04 Oct 2008
Online Status: Offline
Posts: 13
Quote rptfan Replybullet Posted: 04 Oct 2008 at 3:04pm
OK. I don't really under stand using the sum functions in formulas.

But first, the paramaters {?DateFrom} and {?DateTo} can be used in the "select expert" so you only get data in that range. Then everything you sum, will be in that range, because only data in that range will be allowed on the report.

Here's how I do sums.

In a group heading, put a formula like this to set and reset the sum:

shared numbervar mySumEmployeeOne := 0;
shared numbervar mySumEmployeeTwo := 0;
...;
shared numbervar mySumEmployeeTen := 0;

In the group footer, put a formula like this for each employee:

shared numbervar mySumEmployeeOne;

And, in the detail section, put a formula like this:

shared numbervar mySumEmployeeOne;
shared numbervar mySumEmployeeTwo;
...;
shared numbervar mySumEmployeeTen;

//could also use select case for this
if {tblLaborDetail.intEmployeeNumber} = 1 then {
     mySumEmployeeOne := mySumEmployeeOne + {tblLaborDetail.intPayHours};
};

if {tblLaborDetail.intEmployeeNumber} = 2 then {
     mySumEmployeeTwo := mySumEmployeeTwo + {tblLaborDetail.intPayHours};
};

...;
//Keep doing this for each employee.

Let me know if this helps any.
Save money deploying Crystal Reports!
Try a Crystal Reports Viewer.
Refresh data. Export and manage reports.
Easy to use. Free to try.
IP IP Logged
Duward
Newbie
Newbie
Avatar

Joined: 02 Oct 2008
Location: United States
Online Status: Offline
Posts: 5
Quote Duward Replybullet Posted: 04 Oct 2008 at 9:35pm
I am using the date in the select I just put them in the basic formula to try and get a for next loop which looking back I could have just done a 1 to 7.  This report is called from a core application web based program where the user can select the dates but they usally only select the last weeks report to pay a temp agency.  unfortunitly they want a lot of detail broken down by each employee.  I tried doing a sub report but found out I couldn't pass variables back to the main report so I abanded that idea.  I am going to go and try your idea right now because it looks like exzctly what I want.  I thank you very much for your post this problem has been making me loose sleep.     I am mainly a VB programmer so I would have done a do while loop and inside that do a sql select sum query and it would have been great but I don't know how to do this in crystal because I am fairly new to crystal.
 


Edited by Duward - 05 Oct 2008 at 2:33pm
IP IP Logged
rptfan
Newbie
Newbie
Avatar

Joined: 04 Oct 2008
Online Status: Offline
Posts: 13
Quote rptfan Replybullet Posted: 04 Oct 2008 at 10:14pm
Right on. I have the same trouble getting around Crystal. It's seems like most things are much easier to just write a program.

That being said, Crystal runs like a loop, when you group by something. So, use your query, group by the employee id or name. The you have a group header, footer, and detail in the middle.

So, you would have a report that looks something like this:

GH1... Employee 1 start loop
Detail Line... Hour one (or whatever)
Detail Line... Hour two
...
Detail Line... Hour ten
GF1... End Employee 2 Loop
GH1... Employee 1 start loop
Detail Line... Hour one (or whatever)
Detail Line... Hour two
...
Detail Line... Hour ten
GF1... End Employee 2 Loop
Report Footer... Displays all the results from formulas

So, then use the formulas I suggest above, and you can calculate totals, and display at the bottom. That's if you want to have employee names in a row at the top, and have sort of display on the same line. Really, you don't even have to group to do that. You can use the page header to initalize the values, and the footer to display them, and suppress the detail.

That would work with a table with the following format:

Table
-----
Employee ID <---group by this
Work Date <---- Used to filter
Hours Worked <---- Field you want to sum

Anyway, it's hard to really know what you are going for just from post on a message board. It'd be better to see a sample report drawn out, and to have access to your database. Hope I sparked some ideas. Good luck.
Save money deploying Crystal Reports!
Try a Crystal Reports Viewer.
Refresh data. Export and manage reports.
Easy to use. Free to try.
IP IP Logged
Duward
Newbie
Newbie
Avatar

Joined: 02 Oct 2008
Location: United States
Online Status: Offline
Posts: 5
Quote Duward Replybullet Posted: 04 Oct 2008 at 10:31pm

I feel bad about bugging you but I have one more question.  For your variable that you showed I tried to do this because the number of employees is dynamic so I can't set a number.  But Crystal doesn't accept a concatenate as a variable apparently.  Should I use an array or am I just doing the concatenate wrong.  I get the error that the variable needs to be a number.

 

NumberVar i;

For i := 1 To Maximum ({LaborAlias.intRecordID}) Do

(

If {LaborAlias.intRecordID_Contact_Employee} = i Then

shared numbervar   mySumEmployee & i;

mySumEmployee & i := mySumEmployee & i + {tblLaborDetail.intPayHours};

);

 

IP IP Logged
rptfan
Newbie
Newbie
Avatar

Joined: 04 Oct 2008
Online Status: Offline
Posts: 13
Quote rptfan Replybullet Posted: 04 Oct 2008 at 11:05pm
There are two functions... totext() and tonumber().

You concatenate strings with the plus sign.

stringvar whatever := totext({empnum}) + totext({anothernum});

tonumber(whatever)

Does that make sense?
Save money deploying Crystal Reports!
Try a Crystal Reports Viewer.
Refresh data. Export and manage reports.
Easy to use. Free to try.
IP IP Logged
rptfan
Newbie
Newbie
Avatar

Joined: 04 Oct 2008
Online Status: Offline
Posts: 13
Quote rptfan Replybullet Posted: 04 Oct 2008 at 11:18pm
You can use array, but they are static, and may be limited to one hundred elements. So, there's no real advantage of using them, over declaring a standard var for each employee, that I can see.

It seems like with your loop, you are trying to do them dynamically.

Maybe declare your array (you'll have to check the syntax) and then place them in each spot.

shared stringvar myEmployeeArray[100];
shared numbervar myEmployeeTotal[100];
//maybe write a loop to set them all to zero, or figure out how to initalize them correctly

NumberVar i;
For i := 1 To Maximum ({LaborAlias.intRecordID}) Do
(
myEmployeeArray := {employeeName};
myEmployeeTotal := myEmployeeTotal + {valueToSum};
);

Save money deploying Crystal Reports!
Try a Crystal Reports Viewer.
Refresh data. Export and manage reports.
Easy to use. Free to try.
IP IP Logged
Duward
Newbie
Newbie
Avatar

Joined: 02 Oct 2008
Location: United States
Online Status: Offline
Posts: 5
Quote Duward Replybullet Posted: 05 Oct 2008 at 2:40pm
Thank you very much I have achieved what I needed.  I was able to do it using just one variable instead of having to concantenate.  By doing what you suggested to start with, only I did it in the employee group.  I reset this variable at the header of each employee,  and add to it in the detail and show the sum in the footer of this group.
 
Header:
shared numbervar mySumEmployee := 0;
 
Detail (But suppressed because I already have the detail printing correctly.):
shared numbervar   mySumEmployee;
If Sum({tblLaborDetail.intPayHours}, {tblLaborDetail.dteStartActivityDate}, "daily") > 8 Then
    mySumEmployee := mySumEmployee + 8
Else
    mySumEmployee := mySumEmployee + Sum({tblLaborDetail.intPayHours}, {tblLaborDetail.dteStartActivityDate}, "daily")
 
Footer:
shared numbervar mySumEmployee;
 
I will do this for each needed total RegularHours, OT1, and OT2.
 
You have been a great help in leading me down the correct path.


Edited by Duward - 05 Oct 2008 at 2:42pm
IP IP Logged
Page  of 2 Next >>
Post Reply Post New Topic
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



This page was generated in 0.031 seconds.