Custom calculation for Totals in cross tab

In a cross tab report, Is it possible to calculate the total? I must use a different formula.

Comments

  • gpigpi
    edited 12:14AM
    Yes, it's possible. Calculate in the TfrxCrossView.OnPrintCell event, print custom total in the TfrxCrossView.OnPrintCell event. Use TfrxCrossView.IsGrandTotalRow to determine grand total row
  • edited 12:14AM
    I think I have a complex problem and it looks like it can only be solved with complex code.

    But, can you tell me if there is an easy way? See attachment.

    The Percent Row is Term/Active and is already calculated per row. Calculating the grand line total is not hard, but the hard part is the subtotals because it seems I need to have an array to remember the column amounts.

    Is there is an easy way to do this or is this a hard problem?
  • gpigpi
    edited 12:14AM
    I don't found any attachment
    I think no other way, but array usage not a hard problem
  • edited 12:14AM
    gpi wrote: »
    I don't found any attachment
    I think no other way, but array usage not a hard problem

    Sorry I was interrupted at work and quickly sent this message without adding the attachment. Attachment is added to this message.
  • edited 12:14AM
    The solution turned out to be simple due to the sequence that Fast Reports processes data. I did not have to worry about if the data was in a Total or Grand Total, the following code works anyways. I just don't like hard coding the cell Index and relying on process order, but oh well it works.
    const
      MaxPeriods = 100;
        
    var
      PeriodActive: array[0..MaxPeriods] of Integer;
      PeriodTerm: array[0..MaxPeriods] of Integer;
          
      
    procedure DBCross1OnPrintCell(Memo: TfrxMemoView; RowIndex, ColumnIndex, CellIndex: Integer; RowValues, ColumnValues, Value: Variant);
    var
      PercentTerm: Single;                                                  
    begin
      if CellIndex = 0 then
        PeriodActive[ColumnIndex]:= Value
      else if CellIndex = 1 then
        PeriodTerm[ColumnIndex]:= Value
      else if CellIndex = 2 then
      begin
        if PeriodActive[ColumnIndex] = 0 then
          PercentTerm:= 0
        else
          PercentTerm:= (PeriodTerm[ColumnIndex] / PeriodActive[ColumnIndex]) * 100;                                                                                                                     
        Memo.Text:= Format('%2.2f%%', [PercentTerm]);
      end;              
    end;
    
    procedure Page1OnBeforePrint(Sender: TfrxComponent);
    var
      I: Integer;                                  
    begin
      for I:= 0 to MaxPeriods do
      begin              
        PeriodActive[I]:= 0;                                                      
        PeriodTerm[I]:= 0;
      end;                  
    end;
    
    begin
    
    end.
    

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.