Home RAP

Calculation based on summed values

edited May 2003 in RAP
I am starting this thread over since I think it got buried in another
thread. I am still working on this problem but am getting a better
understanding of what I should be doing. I have just not found how to do it
yet. Here is a shortened version of the problem and Jim Bennett's response
so far...

wrote
your
..snip..

OK, I gather that I need to add a variable that will essentially be a global
variable to the report (probably 2 variables) so I can increment them with
the amount paid and amount billed values as the report generates. Then in
the OnCalc event handler of another TppVariable in my summary band I would
reference those two variables (which would now have the complete report
totals) to compute my final percentage.

The two key questions I have (if the above restatement of your answer is
correct) is how do I add those calculated fields to my dataset and where do
I increment them (I figure it would be in their OnCalc event handler and I
would simply add the value from my data pipeline to the variable)? If I
am way off, or the level of these questions indicate that I have missed some
very basic understanding of how RB and RAP work please also point me to what
to read or what tutorials to look at. I have worked my way through about
half of the tutorials and read about a 1/3 of the Developer's Guide but have
not found how to apply that to what I am trying to do here.

Thanks for your patience and help.

-Carolyn

Comments

  • edited May 2003
    If you have a header, detail, footer, summary report, then simply use 3
    TppVariables in the summary band. Sorry if I got you confused, I thought the
    report was going to be more complicated with subreports/groups and such.

    You don't need a SQL calculated field.

    You don't need to use global RAP variables since you do not have subreports.

    So, here is how I see the solution:

    varTotalPaid will total the amount paid in its OnCalc event handler.

    varTotalBilled will total the amount billed in its OnCalc event handler.

    varPercentage will calculate in its OnCalc the (varTotalPaid.Value /
    varTotalBilled.Value) * 100.

    So, then you have to set the CalcOrder properties to control the order the
    values are calculated
    varTotalPaid.CalcOrder = 0
    varTotalBilled.CalcOrder = 1
    varPercentage.CalcOrder = 2

    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited May 2003
    Ok seems simple enough. I set up a varTotalPaid TppVariable, in its OnCalc
    I have:
    Value := Value + dbpContractBalance['O_TOTAL_PAID']; (note:
    dbpContractBalance is my pipeline)

    This works perfectly. It comes up with the correct value. To test out
    referencing this variable I added another TppVariable called varPercent.
    Eventually this will do the calculation I need. But for now I set it's type
    to also be currency (will change in the final design) so I could display the
    same value as my varTotalPaid variable. In the varPercent OnCalc I have:

    Value := varTotalPaid;

    When I preview the report I get the right value in varTotalPaid (9,347.00),
    but I get a value way out of line in varPercent (108,368,892.00). I have
    the Calc Type for both of these set to veTransversal. If I switch the calc
    type to veReportEnd for varPercent I get a value of 0 in it.

    What is happening?

    Thanks,

    Carolyn

  • edited May 2003
    The percentage variable will calculate on every traversal, but it shouldn't
    matter, as it relies on the other two variables in the summary band. The two
    total variables in the summary band should and do print the correct totals.
    The percentage variable relies on the calc order to be correct, and it
    should work as well. Can you send an example to
    support@digital-metaphors.com that doesn't calculate correctly using DBDEMOS
    data?


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited May 2003
    A light bulb (well maybe a LED) just lit up. I think the reason I was not
    getting the right number in my varPercent was that I was not referring to
    varTotalPaid.Value (just varTotalPaid). Anyway, I replace varPercent with a
    TppLabel and in the OnCalc event for the second (per Calc Order) total I
    calculate I set it up as:

    Value := Value + dbpContractBalance['O_MATCHING_FUNDS'];

    lblPercent.Caption :=IntToStr(Int((Value*100)/(Value+varTotalPaid.Value)));

    And this gives me the correct value! Now I guess the remaining question is:
    Does it matter if I set it up this way, or if I set it up with a third
    TppVariable which calculates this in its OnCalc event?

    Thanks for your patient explanations and help,

    Carolyn

  • edited May 2003
    The OnCalcs will fire before the events on the other controls in the same
    band, so you should be safe with this approach.


    Cheers,

    Jim Bennett
    Digital Metaphors


This discussion has been closed.