Group by two fields in Crystal Reports

亡梦爱人 提交于 2019-12-23 20:14:38

问题


How can I group by two different fields in a Crystal Report?

Foe example :

val1|val2|val3|val6
val1|val12|val3|val7
val11|val2|val3|val8
val11|val12|val3|val9

I want the report to look like

val1 :
=======
val2 
----
val3|val6

val12
-------
val3|val7

val11  :
=========
val2
-----
val3|val8

val12 :
------
val3|val9

回答1:


The generic data provided is rather vague, so I will provide my own to demonstrate (with field names on the first line)

"EmployeeName","WeekNumber","DayOfWeek","HoursWorked"
"John Doe",20,"Monday",8
"John Doe",20,"Tuesday",8
"John Doe",20,"Wednesday",8
"John Doe",21,"Thursday",8
"John Doe",21,"Friday",8
"Jane Doe",20,"Monday",8
"Jane Doe",20,"Tuesday",8
"Jane Doe",21,"Wednesday",8
"Jane Doe",21,"Thursday",8
"Jane Doe",21,"Friday",8

Assuming that I read the question correctly, you would want the report to look like this:

John Doe
   Week: 20
      Monday       8 hours
      Tuesday      8 hours
      Wednesday    8 hours
   Week: 21
      Thursday     8 hours
      Friday       8 hours

Jane Doe
   Week: 20
      Monday       8 hours
      Tuesday      8 hours
   Week: 21
      Wednesday    8 hours
      Thursday     8 hours
      Friday       8 hours

If this is the case, you would group by the "EmployeeName" field first, and then simply add another group for "WeekNumber" via the Insert menu using the Group option. This is pretty straightforward, and you can do summaries on the fields at various levels. The only thing that would get "hairy" with multiple tier of grouping would be if you were calculating fields within the group and wanted to return those calculations to a higher level of grouping for summation, which would require declaring global variables within the report.

For what it's worth, I've been using Crystal Reports heavily for the past 7 years.




回答2:


Not sure on best practices, but what I've used to do similar in the past was a sub report with it's own grouping, within the first group.

So it would look something like this:

MainReportHeader SubReport(?) SubreportHeader Values SubReportFooter MainReportFooter

Again, not a crystal expert, just an idea and something I've used before. There is probably a much easier way.



来源:https://stackoverflow.com/questions/233073/group-by-two-fields-in-crystal-reports

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!