gian_the_man
asked on
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_Rat e}) * {@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
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_Rat
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
ASKER
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...
It doesn't even let me create a Running Total for that fomula...
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.
If Not IsNull({@From To Hours}) Then
(ToNumber({SLA.Onsite_Rate
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.
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?
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?
ASKER
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
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
I suspect {@From To Hours}. What does this do for its living?
ASKER
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
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
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
@FromToHours does have values in it, but SumInvoices1 and 2 showed 0.
Thanks,
Gian
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?
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?
ASKER
What if there is a group and a details section on it?
ASKER
It did work... I played around withthe three fields and it worked.
Thanks a lot Isamu.
Thanks a lot Isamu.
If Not IsNull({@From To Hours}) Then
(ToNumber({SLA.Onsite_Rate
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.