i'm trying to do the following with fastreport and delphi. I have a report containing...
GroupHeader -------> Key to Customer Salesman MasterData -------> CustomerName, Balance GroupFooter -------> Sum(Balance) of Salesman-1 MasterData -------> CustomerName, Balance GroupFooter -------> Sum(Balance) of Salesman-2 MasterData -------> CustomerName, Balance GroupFooter -------> Sum(Balance) of Salesman-3 . . . MasterData -------> CustomerName, Balance GroupFooter -------> Sum(Balance) of Salesman-N
====> Here want to have : Footer-2 -------> SUM( Sum(Balance) of Salesman-1, Sum(Balance) of Salesman-2, Sum(Balance) of Salesman-3 ) (ONLY !!!)
ReportFooter --------> Total Customer Balance.
Has anyone an idea to solve the problem with fastreport script engine?
Thank you.
I would create a report global variable 'salessum'
var
salessum: extended;
procedure MYReportOnStartReport(Sender: TfrxComponent);
begin
salessum := 0.0;
end;
In the OnBeforePrint event of the detail band increment the salessum if it is one of the desired salesmen.
procedure MYReportDetailBeforePrint(Sender: TfrxComponent);
begin
if (mydata.salesmankey = "key 1") or (mydata.salesmankey = "key2") or (...) then
begin
salessum := salessum + mydata.amount;
end;
end;
If you want the extra sum at the end of the report then add a report summary band and in the OnBeforePrint event set the value of the appropriate text field to the formatted string of salessum.
procedure MYReportSummaryBeforePrint(Sender: TfrxComponent);
begin
txtMyBestSalesMenTotal.Text := FormatFloat('#,##0.00', salessum);
end;
Alternatively, if you want the extra sum immediately after the salesman 3 subtotal then add a text field in the salesman group footer band and in the OnBeforePrint event set its visible property to true/false depending on which salesman key you are currently processing and set its value to the value of salessum. You will also need to make sure that the band stretches automatically.
I have started to do pretty much all summing using script and report variable as it becomes so much easier to control when and where they should be incremented or reset or printed etc. Using the built in sum functions (in any reporting system) is only useful for very straightforward totals - which, for some reason, very few of my reports are.
Hope that makes sense (and is what you're actually trying to achieve!).