sum a variable
hi all,
i am new to this reporting tool but i have used others. have a report that
takes a weeks transactions and splits them into 7 variables, one for each
day, this way i can get a total for each group for each day. the problem i
have is that i cannot total these daily variables. if i use a dbcalc there
is no option that i can find to sum a variable, only fields from the sql
select statement. i tried using a variable to calculate the totals, ie
variable11.value := variable11.value + linevalue, this compiles ok but guves
a runtime error.
any help much appreciated.
Cheers
Mark
i am new to this reporting tool but i have used others. have a report that
takes a weeks transactions and splits them into 7 variables, one for each
day, this way i can get a total for each group for each day. the problem i
have is that i cannot total these daily variables. if i use a dbcalc there
is no option that i can find to sum a variable, only fields from the sql
select statement. i tried using a variable to calculate the totals, ie
variable11.value := variable11.value + linevalue, this compiles ok but guves
a runtime error.
any help much appreciated.
Cheers
Mark
This discussion has been closed.
Comments
You will need to place another TppVariable inside the group footer (or where
every you would like the sum) and update its value inside the original
variable's OnCalc event.
----------------------------------------------------------------------
TECH TIP: Performing Calculations
----------------------------------------------------------------------
Calculations can be done either on the data access side
or within ReportBuilder.
When designing reports there are always decisions to be made as to
how much processing to do on the data side versus the report side.
Usually doing more on one side can greatly simplify the other. So it is
often a personal choice based on the power and flexibility of the data
and report tools being used.
DataAccess
----------
a. Use SQL - using SQL you can perform many common calculations:
example: Select FirstName + ' ' + LastName As FullName,
Quantity * Price AS Cost,
b. Delphi TDataSets enable you to create a calculated TField object
and use the DataSet.OnCalcFields event
c. Perform any amount of data processing, summarizing, massaging
etc. to build a result set (query or temp table) to feed to the report.
ReportBuilder
-------------
Calculations in ReportBuilder are performed primarily using
the TppVariable component.
a. Set the Variable.DataType
b. Code the calculations using the Variable.OnCalc event.
c. Use the Timing dialog to control the timing of the OnCalc event.
To access the Timing dialog, right click over the Variable
component and select the Timing... option from the speed menu.
d. Set the LookAhead property to True, when you need to display
summary calculations in the title, header, group header, etc.
e. To perform calculations based on the results of other
calculations use the Calc Order dialog of the band. To access
the Calc Order dialog, right click over the Band component
and select the Calc Order... option from the speed menu.
By using TppVariable components ReportBuilder will take care of caching
intermediate results of accumlated calcs that cross pages.
There are a number of calculation examples in the main demos.dpr
project.
---
Additional Notes:
1. Do NOT use Band.BeforePrint or Band.AfterPrint. These events fire
multiple times and therefore should not be used for calculations.
2. Do NOT store results in variables that exist outside of the reports.
For example - form level variables.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
I already have the variables on the report detail line but i can't update
them.
I have 10 variables on the detial line, 1-7 contain a value that is set from
variable 10, variables 8 and 9 are spare for extra code i am trying
Variable 10 goes soemthing like
case dayofweek(transaction_date) of
1: variable1.value := transaction_value
2: variable2.value := transaction_value
...
end;
I have tried to initialise the variables 11-17 on the group footer to 0 and
then in variable 10 add in
case dayofweek(transaction_date) of
1: variable11.value := variable11.value + transaction_value
2: variable22.value := variable12.value + transaction_value
...
end;
but this doesn't work, it compiles ok but gives an error when i try to
preview it
Cheers
Mark
Is this code in the OnCalc event? Be sure the CalcOrder property of
Variable 10 is set to a number before the other variables. Are you coding
these events in RAP? What error do you see when you try to preview?
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com