SAP Knowledge Base Article - Public

1202772 - How to create a manual running totals in a cross-tab in Crystal Reports?

Symptom

  • The methods used to create a manual running total in a report do not work in a cross-tab.
  • How to create a manual running total in a cross-tab, on a report, in Crystal Reports?

Environment

  • SAP Crystal Reports 2020
  • SAP Crystal Reports 2025

Resolution

  • To create a manual running total in a cross-tab use the Display String option of a summary field on a cross-tab. 
  • Below are general steps on how to create manual running total on a cross-tab for the row, as well as for a column.
      
  • To create a manual running total for a row in a cross-tab:
    1. In Crystal Reports, create a report based on any data source.
    2. Insert a cross-tab, by selecting 'Insert - Cross-Tab'.
    3. In the 'Cross-Tab Expert', add a database fields for the column, one for the rows, and one for the summary.
    4. Add the same field again you want to summarized. The second instance of this field will be used to display the manual running total.
    5. Click the 'Customize Style' tab and under 'Summarized Field', select 'Horizontal'.
    6. Click the 'OK' button to close the 'Cross-Tab Expert' dialog box.
    7. Place the cross-tab in the Report Header section.
    8. On the cross-tab, right click the second summary field and click 'Format Field'.
    9. On the 'Common' tab, click the 'X+2' button next to 'Display Text'.
    10. Enter a formula in the 'Format Formula Editor' to calculate the running total and display the value. The formula will be like:

      global numbervar RowNumber;
      global numbervar RunningTotal;
      global numbervar array SummaryValues;
      global datetimevar ColumnValue;
      If GridRowColumnValue ("<Row Database Field Alias Name>") <> ColumnValue then RowNumber:=0;
      ColumnValue := GridRowColumnValue ("<Database Field Name>");
      RowNumber := RowNumber + 1;
      RunningTotal := 0;
      Redim Preserve SummaryValues[DistinctCount(<Database Field Name>)];
      RunningTotal := SummaryValues[RowNumber] + ToNumber(CurrentFieldValue);
      SummaryValues[RowNumber] := RunningTotal;
      ToText(SummaryValues[RowNumber],0)


      NOTE:
      The Row Database Field Alias Name is the alias assigned to the database field used in the cross-tab.
      The alias for a field can be found in the 'Functions' box of the 'Format Formula Editor' dialog box under 'Formatting Functions' > 'Row or Column Names'.
           
    11. Click the 'Save and close' button to close the 'Format Formula Editor' dialog box.
    12. Click the 'OK' button to close the 'Format Editor' dialog box.
    13. Refresh the report.
    14. A row manual running total will now be displayed in the cross-tab.

  • To create a manual running total for a column in a cross-tab:
    1. In Crystal Reports, create a report based on any data source.
    2. Insert a cross-tab, by selecting 'Insert - Cross-Tab'.
    3. In the 'Cross-Tab Expert', add a database fields for the column, one for the rows, and one for the summary.
    4. Add the same field again you want to summarized. The second instance of this field will be used to display the manual running total.
    5. Click the 'Customize Style' tab and under 'Summarized Field', select 'Horizontal'.
    6. Click the 'OK' button to close the 'Cross-Tab Expert' dialog box.
    7. Place the cross-tab in the Report Header section.
    8. On the cross-tab, right click the second summary field and click 'Format Field'.
    9. On the 'Common' tab, click the 'X+2' button next to 'Display Text'.
    10. Enter a formula in the 'Format Formula Editor' to calculate the running total and display the value. The formula will be like:

      global currencyvar rt;
      global datetimevar column;
      if gridrowcolumnvalue("<Column Database Field Alias Name>") <> column then rt:= 0;
      rt := rt + currentfieldvalue;
      column:= gridrowcolumnvalue("<Column Database Field Name>");
      totext(rt)

      NOTE:
      The Column Database Field Alias Name is the alias assigned to the database field used in the cross-tab.
      The alias for a field can be found in the 'Functions' box of the 'Format Formula Editor' dialog box under 'Formatting Functions' > 'Row or Column Names'.
             
    11. Click the 'Save and close' button to close the 'Format Formula Editor' dialog box.
    12. Click the 'OK' button to close the 'Format Editor' dialog box.
    13. Refresh the report.
    14. A row manual running total will now be displayed in the cross-tab.

Keywords

cr, cross-tab crosstab manual running total  , KBA , BI-RA-CR , Crystal Reports designer or Business View Manager , How To

Product

SAP Crystal Reports 2020 ; SAP Crystal Reports 2025