1
votes

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
3

3 Answers

6
votes

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.
6
votes

I would like to suggest an easy solution:-

  • Just Add another group in the GroupExpert i.e. Name mean also group the report by Name
  • Then sort the report via Name by getting to GroupExpert->Option
  • Hide or Suppress the newly added group 'Name' in the report That is all...
0
votes

Your problem doesn't make any sense... If you have one PO Number who have only (unique) Name why then group by one attribute and sort by the other one? You have relation 1:1 which means if you group by PO then you get result :

PO_1         Name_4
P0_2         Name_2

If you group by Name then you get:

Name_1       PO_4
Name_2       PO_1

And that's it... You group by a attribute by which you want to sort by. If you have relation 1:N then this whole problem is solved by another way, but this is not important to this question. Your solution with "suppressing" field work also but it's slower because you first group by some attribute, then suppress details, then calculating sum of it etc... this solution is a lot simplier