views:

7164

answers:

3

how can i group by two different fields in a crystal report.

Foe ex :

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

A: 

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.

thismat
See smbarbour's comments for that much easier way I was talking about.
thismat
+2  A: 

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.

smbarbour
A: 

Dear Smbarbour's Your answer to this question is very detail. However i have a similar problem which. I have 3 tables 1. for Employer details,2.jOB DETAILS 3. jOBS DONE BY EACH EMPLYER TABLE.

I want to group the by job title by employee_id. The problem am have now is one name will come several times with different eid. Hope my question is clear. thank you