Search code examples
crystal-reports

Duplicates in sub-report


I have crystal report with a sub report in it. The sub report is displaying duplicates. To avoid that I used below formula.

{table.IDField} = previous({table.IDField})

Now, duplicates are removed but I have sum of the field in the footer. All the duplicate values are added to the sum. Is there a way that I can select distinct records in the sub report?


Solution

  • I followed below steps to solve this issue.

    1. Created a group on the IDField
    2. Moved all the fields from detail section to the above group header.
    3. Suppressed the detail section.
    4. Created the below formula and placed it in group header. I have supressed this because I didn't have to display this.

      whileprintingrecords;
          numbervar totalOfIDField := totalOfIDField + {IDField};
          "";
      
    5. Created a formula to display the above field (totalOfIDField).

      whileprintingrecords;
      numbervar taotalOfIDField;
      

      This should be placed in the corresponding Group Footer.

    6. Created a formula to reset the totalOfIDField each time group changes. Included this in the Main Group Header.

      whileprintingrecords;
      numbervar totalOfIDField := 0;