Group by two fields in Crystal Reports

crystal-reportsgrouping

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

Best Answer

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.

Related Topic