简体   繁体   English

如何使用Crystal Report按一个字段分组并按另一个字段排序

[英]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. 我想使用Crystal Report按一个字段分组并按另一个字段排序。

For example: Group A with PO Number (sort ASC). 例如: Group APO Number (按ASC排序)。 For each PO Number, there is one Name with it and I would like to sort by Name_x . 对于每个PO号,都有一个名称,我想按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. 我试图用“ Record sort Expert添加一个字段,或者用Name_x创建了一个新组,然后按一个新的组进行排序,但它不起作用。

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

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. 步骤1:在详细信息部分的下面插入新的部分。
  • Step 2: Drag or add fields you wish to use for sorting to a details section of the report. 步骤2:将要用于排序的字段拖动或添加到报告的详细信息部分。 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). 步骤3:右键单击任何字段以为每个字段插入摘要(INSERT | SUMMARY或单击工具栏上的sigma),使用MAX值作为摘要,并为每个部分插入Group Footer(不是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" 步骤4:同样,您可以选择添加单独的组页脚部分,并使用“如果空白部分则抑制”或“抑制”
  • Step 5: Use REPORT | 步骤5:使用REPORT | GROUP SORT EXPERT to choose your sort parameters with new MAX value (ASC or DESC). GROUP SORT EXPERT可使用新的MAX值(ASC或DESC)选择排序参数。
  • Step 6: Suppress group or details if it is necessary. 步骤6:如有必要,隐藏组或详细信息。

I would like to suggest an easy solution:- 我想提出一个简单的解决方案:

  • Just Add another group in the GroupExpert ie Name mean also group the report by Name 只需在GroupExpert中添加另一个组,即Name即可按Name将报告分组
  • Then sort the report via Name by getting to GroupExpert->Option 然后通过转到GroupExpert-> Option通过名称对报告进行排序
  • Hide or Suppress the newly added group 'Name' in the report That is all... 隐藏或隐藏报告中新添加的组“名称”。

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? 您的问题没有任何意义...如果您有一个仅具有(唯一)名称的PO号,为什么要按一个属性分组并按另一个属性排序? You have relation 1:1 which means if you group by PO then you get result : 您具有1:1关系,这意味着如果按PO分组,则会得到结果:

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. 如果您具有关系1:N,则可以用另一种方法解决整个问题,但这对这个问题并不重要。 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 您使用“抑制”字段的解决方案也可以工作,但它的速度较慢,因为您首先按某个属性分组,然后抑制细节,然后计算其总和,等等。此解决方案非常简单

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM