Same Totals??

PixelPointerPixelPointer Vaughan, Ontario
edited 8:17AM in FastReport 3.0
<span style='color:blue'>With my current assignment at work, I am certainly running up a few forum posts. I apologise for posting so much, I usually spend about an hour or so trying to find the solution myself, and then I post here. So, here we go again...</span>

I am attempting to sum up Totals for the entire report, and totals for a grouping, and use each in the same row, for different calculations. Basically, I am finding the percentage usage on a whole, and the percentage usage by a summary group. Here is the code that I am using:
procedure ReportSummary1OnBeforePrint(Sender: TfrxComponent);
begin
       if not Engine.FinalPass then
       begin
               //Sum the prices and profit dollars for the entire report                                                                                                                          
               Set(<extSGRevenues>, Sum(<Price>, MasterData1,1));
               Set(<extSGProfitDollars>, Sum(<ProfitDollars>, MasterData1,1));
       end;
end;

procedure gfSummaryGroupOnBeforePrint(Sender: TfrxComponent);
begin
       if not Engine.FinalPass then
       begin
               //Sum the prices and profit dollars only for summary group                                                                                                                          
               Set(<extRCRevenues>, Sum(<Price>, MasterData1));
               Set(<extRCProfitDollars>, Sum(<ProfitDollars>, MasterData1));
       end;
end;

The issue that I am running into, is that both totals are showing up the same. Where I want the <span style='color:purple'><extRCRevenues></span> variable to hold the sums for each summary group, and the <span style='color:purple'><extSGRevenues></span> to hold the summary for the entire report.

As always, any assistance is GREATLY appreciated.

Comments

  • PixelPointerPixelPointer Vaughan, Ontario
    edited 8:17AM
    In my search, I found, using the showMessage function, that in the ReportSummary1 obp event, the sum of <price> is correct, but the assingnment to extSGRevenues is incorrect. For some reason, extSGRevenues is being set to the total of the first grouping, and not the report total, as it should be. ;)
  • PixelPointerPixelPointer Vaughan, Ontario
    edited 8:17AM
    Ok, I really don't get it, and I am really getting frustrated with this reporting tool! I was using the built in variables list to add variables, but I thought that maybe that was my issue, so I created new variables of type double, and then initialized them to zero during the FFReport ors event. Again, using a message box, I can see that my values for the summation are correct, however the variables are not being set properly. Immediately after being set, they show a value of 0, once the report is complete, they contain a value, but it is identical, even though they are in different bands. ;)

    This is a portion of my code, if anyone has the time to look @ it.
    var
    NewRCRevenues: Double;
    NewSGRevenues: Double;
    
    procedure memPercentRelatedOnBeforePrint(Sender: TfrxComponent);
    begin
        if Engine.FinalPass then
           begin
                   if Get(<NewRCRevenues>) > 0 then
                   begin
                           memPercentRelated.Text := FormatFloat('0.000',(<Price> / Get(<NewRCRevenues>) * 100));
                   end
                   else
                   begin
                           memPercentRelated.Text := '0.000';
                   end;
           end;
    end;
    
    procedure memPercentTotalOnBeforePrint(Sender: TfrxComponent);
    begin
      if Engine.FinalPass then
           begin
                   if Get(<NewSGRevenues>) > 0 then
                   begin
                           memPercentTotal.Text := FormatFloat('0.000',(<ProfitDollars> / Get(<NewSGRevenues>) * 100));
                   end
                   else
                   begin
                           memPercentTotal.Text := '0.000';
                   end;
           end;
    end;
    
    procedure ReportSummary1OnBeforePrint(Sender: TfrxComponent);
    begin
           if not Engine.FinalPass then
           begin
                   { Aggregate the prices for the entire report }
                   Set(<NewSGRevenues>, Sum(<Price>, MasterData1,1));
                   showMessage('SG-Sum<Price> ' + FloatToStr( Sum(<Price>, MasterData1,1)));
                   showMessage('NewSGRevenues ' + FloatToStr(<NewSGRevenues>));
           end;
    end;
    
    procedure gfSummaryGroupOnBeforePrint(Sender: TfrxComponent);
    begin
           if not Engine.FinalPass then
           begin
                   { Aggregate the prices for summary group }
                   Set(<NewRCRevenues>, Sum(<Price>, MasterData1));
                   showMessage('RC-Sum<Price> ' + FloatToStr( Sum(<Price>, MasterData1,1)));
                   showMessage('NewRCRevenues ' + FloatToStr(<NewRCRevenues>));
           end;
    end;
    
    procedure FFReportOnStartReport(Sender: TfrxComponent);
    begin
      NewRCRevenues:=0;
      NewSGRevenues:=0;
    
    end;
    
    begin
    end.
    

    I have about 10 reports to write, that are similar to this one, but this one has taken me over a week!!! So, if anyone has a solution, I will certainly give it a try, and will be very appreciative.

    Thank you.
  • edited 8:17AM
    Hi, I think there is a demo on FastReport intallation path for something like that.

    Actually, it don't use Script, but a memo expression.

    Have you tried it?

    Btw: FastReport is an excelent Report tool if you never try to use its Script! ;)
  • PixelPointerPixelPointer Vaughan, Ontario
    edited 8:17AM
    I had previously downloaded the Fast Reports demo, and got a lot of this code from it, and then simply adjusted it to fit my needs. For one sum, it seems to work ok, but in total, I need 4 sums. From what I have seen so far, the variables don't seem to be getting set properly, as the numbers are accurate at each point when the variables are set. I am more frustrated now, than when I first used Win 3.1!!!
  • gordkgordk St.Catherines On. Canada.
    edited 8:17AM
    It is even more excellent when using code script.
    You are probably setting values in the wrong place or event.
    Frustration usually comes from hacking code from demos and trying to adapt without understanding why and where it was written.
    Been there done that.

    variables declared at the top of the code page are global to the report
    can be used in any object event and displayed in a memo by enclosing in [ ]
    you can initialize them in the empty begin end block at the bottom of the code page no need to add a procedure to initialize them, this is the first piece of code to run. one must pay attention to where they may be reinitialized
    they can be retreived/modified with out using the get set methods, which are used with categorized variables in the variable list.
    the best bet is to design layout first then write the code to suit
    a lot of things can be accomplished just using expressions and functions in the memos themselves, also setting the displayformat prop of the memo and using an intermediate var for display purposes can save writing a lot of code converting to formated strings and changing text of memos.
    one caveat when using grouping it will not perform correctly with unidirectional datasets like DBX.
    ;)
  • PixelPointerPixelPointer Vaughan, Ontario
    edited February 2006
    Thank you, gordk, I appreciate you taking the time to respond to my post. Yes, a lot of my frustration is coming from not knowing what my script can and cannot do. I have programmed in VB, C#, and C for many years, so I at least have some programming knowledge. I only bastardize the code because I would rather take what is already written, than re-write from scratch. The code makes sense to me, however, obviuosly there is something that I think I have my head around, that I really don't. :-) Now, THERE is my frustration. The company for whom I work, has already purchased this tool, and has integrated it into our software package, so I don't have much of a choice, but to make this work. There are only 2 things that I am missing, that would complete my report writing.

    (1) being able to do calculations based on summed columns from various levels of grouping
    (2) an automated export to csv

    Once I conqueur those two issues, I am off to the races. :-) I will continue to plug away, and hopefully I will get these variable settings working.
  • gordkgordk St.Catherines On. Canada.
    edited 8:17AM
    if your programmer included the export components in the app
    when you preview the report you should be able to export to the format of your choice.
    read the usermanual chapter on working with aggregates around pg 61 IIRC
    BTW what version of fr and delphi are being used?
  • PixelPointerPixelPointer Vaughan, Ontario
    edited 8:17AM
    Thank you for your response, gordk. I have been away visiting clients for a few days, and did not check my posts.

    For Delphi, it is V5, for FR it is 3.20.

    I have read the aggregates functions in the manual, and I am pretty sure that I have a good idea of how they work, however, I still can't get this thing to work. At first, the task seemed pretty simple, add up 3 columns, take the sum at the bottom, and divide each value in the list by the sum to get the percentage of total for each value. I was able to get one column to work, but thats it so far.

    As for exporting, I can export manually from the reports, but I am tring to put together a script that will allow the customer to use our scheduler to schedule the reports, and have them exported automatically. :-(

    Since my last bad attitude post, I have built quite a number of simple reports in Fast Reports, and I was able to build them quite quickly. Its just these last two issues that have created a dent in my desk the size of my forehead.
  • PixelPointerPixelPointer Vaughan, Ontario
    edited 8:17AM
    So, if I chose not to use script, is there a way to tell fast reports, in a memo field that I want the value of the current row divided by the sum of the values?

    i.e.

    Sales | % of Sales
    $12 | 0.150
    $10 | 0.125
    $34 | 0.425
    $24 | 0.300
    $80 | 1.000
  • gordkgordk St.Catherines On. Canada.
    edited 8:17AM
    Hi pixelpointer go to the binaries newsgroup
    ill post a modified version of 45.frf from the main frdemo for you
    the subject will be modified frf for pixelpointer.
  • PixelPointerPixelPointer Vaughan, Ontario
    edited 8:17AM
    Awseome! Thank you.
  • PixelPointerPixelPointer Vaughan, Ontario
    edited January 2007
    Got it.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.