SAP Knowledge Base Article - Public

1655860 - Running total for distinct field values in CR

Symptom

Running total is not possible for distinct values of a number field with duplicate values in Crystal Reports

Environment

Crystal Report 2008 (All Versions)

Reproducing the Issue

  1. Create a Crystal Report with a number field which containing duplicate values.
  2. Apply running total or sum those values it will give sum for all the values.

Resolution

We need to populate the distinct values in an array and finally add them up.
1. Open Crystal Report designer and Create the following formula

whileprintingrecords;
numbervar array arr;
numbervar i := recordnumber;
redim preserve arr[i];
if not({<Field name>} in arr) then
   arr[i] := {<Field name>};

2. Place above formula in the section which holds the total scanned value
3. Create another formula and place this on the report footer:

whileprintingrecords;
numbervar array arr;
numbervar result;
numbervar j;
for j := 1 to ubound(arr) step 1 do
(
   result := result + arr[j]
);
result;

Keywords

Distinct sum, distinct running total , KBA , BI-RA-CR-DSL , Crystal Reports on Data Semantic Layer , How To

Product

SAP Crystal Reports all versions