PDA

Click to See Complete Forum and Search --> : problem with a running total in a group


r0k3t
Nov 4th, 2008, 01:10 PM
Hi there,

I have created this formula to hold my running total. It look like this...

WhilePrintingRecords;
NumberVar totalHours;
totalHours := totalHours + {GetEmployeeHoursAllByDate.Hours};


And in the header for each grouping I have this.

WhilePrintingRecords;
NumberVar totalHours := 0;

which resets the total at the beginning of every grouping.
It works fine when I look at the formula in the detail section but if I put the total hours formula in the footer it is totally wrong in a way I can't understand sometimes wildly under or over and sometimes it has the value of the last Hours field.

Hopefully I have made my problem clear and someone out there has a suggestion for how to get this right.

Thanks!

r0k3t
Nov 4th, 2008, 01:29 PM
Ahh - I see what is happening, it is adding the last hour fields amount to the total.

Is there some way I can say - If you are in the footer don't continue to add?

Thanks

brucevde
Nov 4th, 2008, 04:30 PM
Create another formula that returns the current value of the TotalHours variable and place it in the footer section. The formula that calculates the total must be in the Details Section but can be suppressed.
WhilePrintingRecords;
NumberVar totalHours;

But why use a running total when you can simply use the following formula placed in the footer section.

Sum ({GetEmployeeHoursAllByDate.Hours}, {GetEmployeeHoursAllByDate.Name of Field used for Group};})

r0k3t
Nov 5th, 2008, 10:11 AM
Uhm, I don't know - Because I just got this Crystal thing dumped on me :)

Here is the issue. In the case of the total hours there is no problem, I am adding up everything but I have several others that are conditional to the "account" or "chart" as it is called. For instance I have this for personal time

WhilePrintingRecords;

NumberVar personalHours;
if(({GetEmployeeHoursAllByDate.Chart} = "8760") or ({GetEmployeeHoursAllByDate.Chart} = "8761") or ({GetEmployeeHoursAllByDate.Chart} = "8765") or ({GetEmployeeHoursAllByDate.Chart} = "8775"))
then
personalHours := personalHours + {GetEmployeeHoursAllByDate.Hours}
else
personalHours


I mean don't get me wrong - there so probably is a better way to do this - it is just what I figured out knowing not much at all about C.R.

Thanks for any advice.

brucevde
Nov 5th, 2008, 10:47 AM
I mean don't get me wrong - there so probably is a better way to do this - it is just what I figured out knowing not much at all about C.R. FYI. There is a Running Total feature built into Crystal. I don't know your CR Version but you usually access the Running Total gui from the same menu used to create Formulas.

r0k3t
Nov 5th, 2008, 02:00 PM
right I tried that for some time, I just couldn't get it to work with any conditions like the chart, it was just always be blank... *Shrug*