0
votes

I have a report that is doing a running total manually ie:

shared numbervar Amount:={#Amount};
shared numbervar TotalAmount:=Amount+TotalAmount;
Amount;

I then have a separate formula attempting to calculate the average by dividing the amount by the total amount:

whileprintingrecords;
shared numbervar TotalAmount;
if {@Amount}<>0
then
{@Amount}/TotalAmount;

Despite using whileprintingrecords, the Total Amount is not displaying the actual total, it's displaying the total at the time Amount is printed. So what am I doing wrong?

Edit: Both formulas are in the footer of a group. As a test I even removed the groups, and had them both in the details section, with no groups present. I even removed the running total to try and take it out of the mix, with no change.

I'm trying to calculate the percentage each amount contributes to the total amount. So the report would look like

Amount | %
$100   | 50%
$50    | 25%
$50    | 25%
____ 
$200

Instead the report ends up looking like:

Amount | %
$100   | 100%
$50    | 33%
$50    | 25%
____ 
$200
1
It's hard to understand what you are trying to do. Where exactly are you placing each of these formulas in the report? It matters a lot where you place them because that's how crystal is going to update your variables. Can you maybe add some sample data and what you are trying to do? - SOfanatic

1 Answers

0
votes

There can be lot of issues why calculation is not carried to the next formula

  1. Placement of your 2nd formula may be wrong compared to first formula placement in report.
  2. along with whileprintningrecords also try using EvaluateAfter.

whileprintingrecords; EvaluateAfter(@Formula1); shared numbervar TotalAmount; if {@Amount}<>0 then {@Amount}/TotalAmount;

Edit--------------------------------------------------------------------------------------------- Problem for you here is at each level it is taking the total amount not the final value. Like at first record value is 100 and @amount is 100..now 100/100 is 100% now at second record value is 50 and @amount is 150 so % is 50/150 it is 33.33. Best option would be use the sub report and pass the final value that is 200 as the input value to sub report and display your data in sub report.