Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Summarising two lookup tables with many records Post Reply Post New Topic
Author Message
JonC
Newbie
Newbie


Joined: 08 Jan 2009
Location: England
Online Status: Offline
Posts: 2
Quote JonC Replybullet Topic: Summarising two lookup tables with many records
     Posted: 08 Jan 2009 at 12:41pm
Hello, I'm sure somebody has had this same requirement, but after a long time trying I cannot get this right. Scenario:
 
Parent Table contains one record per Job Code
 
Lookup table 1 contains many records per Job Code with rate, quantity and value of work carried out on that job.
 
Lookup table 2 contains many records per Job Code with expenditure details for that job.
 
How could I present this data in a report that summarises by Job Code a field in each of the lookup tables, such that the summaries can be used in calculations.
 
The actual scenario is more complex than this, but this is the basic premise of my problem.
 
The report would look like this:
 
 
Job Code: 23560
 
Income:
Item     Quant   Rate    Total
101               2      20       40
102               3      40      120
                                       ___
                                       160
Expenditure:
Item          Cost
     1              50
     2              60
     3              10
                  ____
                   120
 
Profit/Loss = 40
 
Next job........etc
 
 
I've tried using subreports, but in a much more complex scenario, the summaries of seperate subs cannot be used in a formula of the main report. I've also tried using queries to first summarise data, but depending on the linking, the detail lines get returned more than once.
 
Anyone dealt with this?
 
 
 
 
 
 
 
 
 
 
 
 
 
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 09 Jan 2009 at 11:22am

Can' say that I have had this exact situation, but here is how I would attack the issue:

I would link the look up tables to the main table (it probably already is but...)
 
Make a group for the job code.  As I think, I would try 2 subreports that link on the job code and this will allow you to get the cost and expenditures displayed with their appropriate subtotals.  Hopefully, you have gotten this far before, the last part would be how to get the profit/loss amount.  In the group footer I would display a formula.  The formula would be something like:
 
SUM({table1.costfield}, {maintable.jobcode}) - SUM({table2.expensefield}, {maintable.jobcode})  // the maintable.jobcode would be the group criteria
 
Is this what you are looking for?  For the report footer if a total profit/loss was desired you would just remove the group citeria from the formula so that all costs and expenses woudl be displayed.
 
Hope this helps
IP IP Logged
RitaInHood
Newbie
Newbie


Joined: 07 Jul 2008
Online Status: Offline
Posts: 25
Quote RitaInHood Replybullet Posted: 12 Jan 2009 at 8:50am
I've tried using subreports, but in a much more complex scenario, the summaries of seperate subs cannot be used in a formula of the main report. .

I disagree - declare a shared variable in the main report header, then in the group header just above the subreport, set the variable :=0.  Total up your subreport, and then set the shared variable := total.  Back in the main report, display the shared variable.  Use this displayed shared variable in your main report formulas.

I admit its a bit of a pain to set up, but it works swell.
IP IP Logged
JonC
Newbie
Newbie


Joined: 08 Jan 2009
Location: England
Online Status: Offline
Posts: 2
Quote JonC Replybullet Posted: 13 Jan 2009 at 9:54am
Thanks for the help. I have succeeded with the shared variables.
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