Adding a total of a formula field

Hi people...
I got an issue at hand. The field @Invocie is a formula consisting of the following:

If Not IsNull({@From To Hours}) Then
$(ToNumber({SLA.Onsite_Rate}) * {@From To Hours})
Else $0.00

It displays the invoice total of each client. My boss wants a total revenue field displaying the SUM of all invoices. However, I can't do a running total on that sum (due to the formula?).
What's the best way to add the value of each result?

Thanks,

Gian
gian_the_manAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

frodomanCommented:
Make your formula like this:

If Not IsNull({@From To Hours}) Then
   (ToNumber({SLA.Onsite_Rate}) * {@From To Hours})
Else
   0

This will give you a numeric result so you can add a total.  Use the field format to display the currency symbol instead of adding it to your result manually.

gian_the_manAuthor Commented:
I still get 0 as the total if I take out the $.
It doesn't even let me create a Running Total for that fomula...
frodomanCommented:
Maybe this:

If Not IsNull({@From To Hours}) Then
   (ToNumber({SLA.Onsite_Rate}) * ToNumber({@From To Hours}))
Else
   0


Another possibility - will {SLA.Onsite_Rate} ever be null? Maybe need to add a check for that also?


Sorry, but that's all I can think of.  I've never not been able to create a running total so I suspect is has to do with non-numeric results.
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

Ken TurnerCommented:
I've just tried reproducing your problem - I re-created your original formula changing nothing except the variables, and made sure it was error-free.  I also confirmed that it produced a numneric rather than a text result.

I then successfully created a running total of this formula.

So what am I doing that's different?  What flavour of Crystal Reports are you using?  (I'm on CR8.0).   What happens when you attempt to create the running total?
gian_the_manAuthor Commented:
I'm running Crystal 8.0...
The problem I have is that I just can't see the formula when trying to create a Running Total field. It just won't let me do it...
I don't know why, but the formula @Invoice is not listed as an option to do a running total of it.

Gian
Ken TurnerCommented:
I suspect {@From To Hours}.  What does this do for its living?
gian_the_manAuthor Commented:
Hello Ken,

You may be right... There is a chain of formulas that goes further. This is the @From To Hours formula:

If Not ISNull({@From To Total})
Then If (ToNumber({SLA.Calls Allotted}-{@From To Total}) >= 0)
Then 0
Else (ToNumber({@From To Total}-{SLA.Calls Allotted}))
Else 0.00

This is the From To Total formula:

NumberVar TotalSecs := {#From To Total Duration};
NumberVar TotalHours;
// NumberVar FracHours := Truncate(TotalSecs / 3600);

If (TotalSecs / 3600) < 1 Then
    TotalHours := 0
Else
    TotalHours := Truncate(TotalSecs / 3600);

NumberVar FracHours := (TotalSecs / 3600) - Truncate(TotalSecs / 3600);
NumberVar TotalMinutes := (FracHours * 60);

If TotalMinutes = 60 Then
    (
        TotalHours := TotalHours + 1;
        TotalMinutes := 0;
    );

ToNumber(Truncate (TotalSecs / 3600, 2));

I increased the points on this since it seems it'll take some more time to figure out.

Thanks for the help...

Gian
EwaldLCommented:
The problem seems to be related with its evaluation time. As far as I know only formulas that are declared as
WhileReadingRecords; in the first line can be used in a running total.

In general, better avoid referencing one formula in the other. as this might lead to multiple execution of the same formula for the same section. Rather have the formula store a result in a shared variable. you can then reference this variable in another formula without having the multiple execution of formula which is bad for performance and could also bring back unwanted results. Then use the evaluateafter() function at the top of the second (and of any more formulas) to specify the sequence the formulas are to be evaluated in.
isamu_2000Commented:
This is an easy thing to solve.
First, in your formula, you don't want the '$' sign.  take that out and put that in a text box where you put $ and drop your invoice formula number field into it.

Then, create a formula called 'SumInvoices0'

In that you will put
'
WhilePrintingRecords;
global numbervar SumInvoices:= 0;
'
Place this in the report header.  I am assuming you want the invoice total at the report footer.
Then make another formula 'SumInvoices1'
'
WhilePrintingRecords;
global numbervar SumInvoices;
SumInvoices := SumInvoices + {@From To Hours}
'

Create a section below where you are listing {@From To Hours} and drop SumInvoices1 in there.  Suppress it.

Now, create one more formula 'SumInvoices2'
'
WhilePrintingRecords;
global numbervar SumInvoices;
SumInvoices := SumInvoices;
'

Place this in your report footer.  It will now display a grand total of all your subtotaled invoice {@From To Hours}.

isamu

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gian_the_manAuthor Commented:
It made sense what you said, but it still returned a value of 0.
@FromToHours does have values in it, but SumInvoices1 and 2 showed 0.

Thanks,

Gian
isamu_2000Commented:
Hmm ... where are you putting the formulas?  The first one should go in the header somewhere, the second should go in the same section that you are subtotaling your @FromToHours to get an individual invoice.  The last one should go in the footer.

I've used this technique several times and have never had too much trouble with it.

Maybe somebody else can see an error I might be making in explaining it?
gian_the_manAuthor Commented:
What if there is a group and a details section on it?
gian_the_manAuthor Commented:
It did work... I played around withthe three fields and it worked.

Thanks a lot Isamu.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.