Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Calculations in Totals

edited February 2003 in General
I have some reports that you might think of as income and expenses,
although there are 3 or 4 categories rather than 2. I display all data
values as absolute numbers and total each category. How can I get grand
totals? I want to add some categories and subtract others (of the 3 or
4).

I can create additional invisible fields with signed values, then simply
add them up. (I think). But I wonder if I can get that much logic into a
variable at the Total level. I don't know how to refer to the sub-total
of each category. These are DBCalcs.

Psuedocode:
Total = (if category is "Income" then Add(Sub-total of category)) +
(if category is "Expense" then Subtract(Sub-total of category));

Thanks,
Patrick

Comments

  • edited February 2003
    The easiest way would be to use one TppVariable in the summary band and in
    its OnCalc event handler, check the data pipeline's record value ( myValue
    := Report.DataPipeline['aFieldName']; ). If it is an expense or income, then
    perform the appropriate operation on the Value in the variable's OnCalc.

    If it is more complicated than that, then you may want to explore creating a
    group on Category. Then use a TppVariable and its OnCalc event handler to
    sum the total for this group, both expenses and income. The problem is going
    to be that the variable will reset when the group ends. So, to workaround
    this issue, use the same OnCalc event handler, but after the total is
    summed, assign the new Value to a variable that is for the grand total. This
    way the inner variable's OnCalc calculates a value from the datapipeline,
    and adds/subtracts it from the grand total.

    Here is an example of group percentages, which shows other techniques for
    performing operations on variables for a grouped report:
    http://www.digital-metaphors.com/tips/PercentageOfGroupTotal.zip


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited February 2003
    Thanks. This gives me some insight into the life of variables that should be
    enough to do what I need.


  • edited February 2003
    Jim,
    I downloaded and studied the tip, combined with your suggestions below with
    some success. It's not perfect yet but I'm concerned with how to fix it. I
    already have a group for income and expense, as you suggest.
    I first declared a variable in the Private section of the type, like your
    F-variables in the tip. I increment (or decrement) those in the group footer
    After generate. Then assigned them below for totals. It almost worked, but kept
    incrementing as I paged back and forth in the preview - which really surprised
    me because I thought once the report was generated it was done.

    Then I removed my Private variables and directly incremented (or decremented)
    the group total to a DBCalc component for the higher group total - trying to use
    your "problem" of having the variable automatically reset on each group. Well
    it's not doing that (resetting) and I am considering manually zeroing it out
    after it prints. Am I making this better or worse?

    Patrick




  • edited February 2003
    First thing to try is to set Report.CachePages to true. The correct behavior
    otherwise is what you are getting, though not what you need in this report.
    The calculations will refire if CachePages is False. Some reports in the
    field rely on this feature in order to work correctly.


    Cheers,

    Jim Bennett
    Digital Metaphors


This discussion has been closed.