Search code examples
sortingcrystal-reports

How to group by one field and sort by another field with Crystal Report


I would like to group by one field and sort by another field with Crystal Report.

For example: Group A with PO Number (sort ASC). For each PO Number, there is one Name with it and I would like to sort by Name_x.

I have tried to add a field with Record sort Expert or I created a new group with Name_x and then sort by a new one but it does not work.

PO_1         Name_4
PO_2         Name_2
PO_3         Name_3
PO_4         Name_1
PO_5         Name_7
PO_6         Name_6

The result must be:

Name_1       PO_4
Name_2       PO_1
Name_3       PO_1
Name_4       PO_1
Name_6       PO_6
Name_7       PO_5

Solution

  • I've found the solution as below and it works pretty well. Please let me know if you have any idea.

    Solution: We will create summaries within each group which we can use for the sort function.

    • Step 1: Insert a new section below in details section.
    • Step 2: Drag or add fields you wish to use for sorting to a details section of the report. Format these fields as Suppressed.
    • Step 3: Right-click on any field to insert a Summary (INSERT |SUMMARY or click sigma on toolbar) for each of these fields, using the MAX value as the summary, and inserting a Group Footer for each section (Not the Report Footer). Repeat for all fields you wish to use for sorting.
    • Step 4: Again, you may choose to add a separate group footer section and use "Suppress if Blank Section" or "Suppress"
    • Step 5: Use REPORT | GROUP SORT EXPERT to choose your sort parameters with new MAX value (ASC or DESC).
    • Step 6: Suppress group or details if it is necessary.