Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: New to CR Post Reply Post New Topic
Author Message
saphir54321
Newbie
Newbie


Joined: 15 Mar 2010
Online Status: Offline
Posts: 9
Quote saphir54321 Replybullet Topic: New to CR
     Posted: 15 Mar 2010 at 7:12am
Hi Everybody,

I'm new with Crystal Report and I have a few questions.

I have a table who has an attribute which is a foreign key of the table itself.
Code:
Company {id, compName}
Department {id, companyId, departmentId, depName}
- we can then have sub departments
- departmentId will be null if it's the top level

Report {id, companyId, report}
Work {id, reportId, departmentId, work}
I need to display something like this:
Code:
Departments Name                         Nb Work
Dep 1 5 //Sum of Sub Dep 11 and SubDep 12
Sub Dep 11 3 // Sum of Sub Sub Dep 111 and Sub Sub Dep 112
Sub Sub Dep 111 1
Sub Sub Dep 112 2
Sub Dep 12 2 // Same process than Sub Dep 11
Sub Sub Dep 121 1
Sub Sub Dep 122 1
Sub Sub Dep 123 0 // I would like to display 0 for the departments without works
Dep 2 4 // Same process than Dep1
Sub Dep 21 1
Sub Dep 22 0
Sub Dep 23 3
What I have so far:

Parameter entered by user:
Sort data by Company.Id AND Report.Id

I have a group on the Department.id
To calculate nb work: count ({Work.departmentId}, Department.id)

How can I:

1) Indent depending on the department level
2) Have zero for the departments without works
3) The sum of the sub departments for departments with sub departments

Thanks a lot

saphir
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 15 Mar 2010 at 9:39am
It depends on how many levels you can have. If the number is finite, you can probably create the correct number of joins by adding the same table into the report multiple times.
 
In my eyes, a simpler solution is to create a stored proc that would basically do the same thing, but is easier for me to craft/understand.  Either way, once you have the data, the rest becomes a 'standard' report.
 
HTH
IP IP Logged
saphir54321
Newbie
Newbie


Joined: 15 Mar 2010
Online Status: Offline
Posts: 9
Quote saphir54321 Replybullet Posted: 16 Mar 2010 at 1:44am
Thanks for your reply lockwelle.

I have 3 levels.

  • I have done it like you said by adding 3 times the same table (with different alias) with the correct join for each table. I've added 3 groups, one for each level. I sorted the data to use the data from the top level. I can indent now depending on the level.
  • I've been looking to the hierarchical grouping option technique as well. I have only 1 time my department table (only 1 group section). I can indent my data depending on the level. It works quite well, except when you indent, the background color and all data next to it are indented as well. :-S

Both of those techniques work to display my departments. 

But my problem is still the same.

How do I calculate the sum for the departments with sub departments?
 
For the hierarchical grouping option.

I lose the departments where I have sub departments when I sort the data with my reportId parameter from the Work table because those departments are not linked with any data in the Work table. That's why I would like to have the sum of the sub departments for those one.
In my example above, as you can see, I need to calculate the sum for Dep 1 (which is the sum of Sub Dep 11 and Sub Dep 12), Sub Dep 11 (which is the sum of Sub Sub Dep 111 and Sub Sub Dep 112), Sub Dep 12 (same process than Sub Dep 11) and Dep 2 (same process than Dep 1)

For the 3 tables option.

Not sure how to display the nb of works by departments. And how to calculate the sum for the departments with sub departments.

Any ideas?  

IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 16 Mar 2010 at 3:22am

I haven't used heirarchical grouping, but with the 3 table option, I would think that a simple SUM() would do the trick.  Something like:

in the department header:
SUM({subsubdepartment.work},{department.work})
 
for the subdepartment header:
SUM({subsubdepartment.work},{subdepartment.work})
 
A formula shouldn't be needed, just add the summation for the group (and it will put it in the group footer, just move it to the group header...aggregates can go in either the footer or the header
 
HTH
IP IP Logged
saphir54321
Newbie
Newbie


Joined: 15 Mar 2010
Online Status: Offline
Posts: 9
Quote saphir54321 Replybullet Posted: 16 Mar 2010 at 4:40am
Thanks again for your quick reply.

Like I said, I have attached 3 times the same table with different alias: (top_departments, sub_departments, subsubdepartments)
I'm still trying to put the information in the sub sub department.
But how do I link Work with subsubdepartments AND sub_departments?
Coz when you don't have sub sub departments for a sub department, then the data in Work are linked with sub department.

Hope this make sense.   Ermm

IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 16 Mar 2010 at 10:19am
sounds like you need an outer join, not inner which is the default.  right click on the link and select Left OR right outer join....I get my data from a stored proc, so I am not sure which way/how CR determines if the table is on the right or the left.  Experiment is the best that I can say, just make all the joins (both of them) the same (right or left outer) and see if the report displays as you want.
IP IP Logged
saphir54321
Newbie
Newbie


Joined: 15 Mar 2010
Online Status: Offline
Posts: 9
Quote saphir54321 Replybullet Posted: 17 Mar 2010 at 1:39am
it doesn't really solve how to link a same attribute from a table to 2 other tables. Unhappy
IP IP Logged
saphir54321
Newbie
Newbie


Joined: 15 Mar 2010
Online Status: Offline
Posts: 9
Quote saphir54321 Replybullet Posted: 22 Mar 2010 at 1:50am
I finally made it work using hierarchical grouping. But I'm still struggling to calculate the sum by department and sub department (if sub sub department).

Departments Name                         Nb Work
Dep 1 5 //Sum of Sub Dep 11 and SubDep 12
Sub Dep 11 3 // Sum of Sub Sub Dep 111 and Sub Sub Dep 112
Sub Sub Dep 111 1
Sub Sub Dep 112 2
Sub Dep 12 2 // Same process than Sub Dep 11
Sub Sub Dep 121 1
Sub Sub Dep 122 1
Sub Sub Dep 123 0 // I would like to display 0 for the departments without works
Dep 2 4 // Same process than Dep1
Sub Dep 21 1
Sub Dep 22 0
Sub Dep 23 3
 
Any ideas?
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum