problem with a running total in a group
Hi there,
I have created this formula to hold my running total. It look like this...
Code:
WhilePrintingRecords;
NumberVar totalHours;
totalHours := totalHours + {GetEmployeeHoursAllByDate.Hours};
And in the header for each grouping I have this.
Code:
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!
Re: problem with a running total in a group
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
Re: problem with a running total in a group
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.
Code:
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};})
Re: problem with a running total in a group
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
Code:
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.
Re: problem with a running total in a group
Quote:
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.
Re: problem with a running total in a group
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*