Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: SUM Value from Linked Table Post Reply Post New Topic
Page  of 2 Next >>
Author Message
DC0826
Newbie
Newbie
Avatar

Joined: 23 Oct 2013
Online Status: Offline
Posts: 5
Quote DC0826 Replybullet Topic: SUM Value from Linked Table
     Posted: 24 Oct 2013 at 2:25am
I am coming back into using Crystal Reports after ten years removed.  My company has a routing software that is sql based and I am writing some custom reports to evaluate route performance.  I have two tables that are linked by route ID.  See below:

Table 1
Route ID   Route Date   Driver Name   Miles Driven   Hours on Route
11111       9/30/2013    xxxxxx            1000              50
22222       9/1/2013      bbbbb             200                 6
33333       9/15/2013    cccccc              100                 8
44444       9/10/2013    ddddd              50                  9
 
Table 2
Route ID  Location ID  Gallons Collected
11111             1a                      5
11111             1b                      6
11111             1c                     10
22222             1d                     25
22222             1e                     30
44444             1f                      20
44444             1g                     30

I want to create a report that shows the following:

Route ID   Route Date   Driver Name   Miles Driven   Hours  Gallon collected
11111       9/30/2013    xxxxxx            1000              50                 21
22222       9/1/2013      bbbbb             200                 6                  55
33333       9/15/2013    cccccc              100                 8                  0
44444       9/10/2013    ddddd              50                  9                  50

I can not get a formula to return the gallons collected for the route id on that line.  What I get is the total gallons collected for that date range on every line and it makes the lines duplicate.  Can some help me with a formula?
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 24 Oct 2013 at 3:59am

join table1 to table2 on routid

group on table1.routeid
hide your details
insert a summarization of table2.gallonscollected at the group  level.
move it to the group header
place table1 fields route date driver name miles and miles driven on GH1.
hide your group footer
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 24 Oct 2013 at 4:01am
also make sure you do a left outer join from table1 to table2 as you have no matching record in table2 for routeid=33333
set your summarization formula to use default values for nulls
IP IP Logged
DC0826
Newbie
Newbie
Avatar

Joined: 23 Oct 2013
Online Status: Offline
Posts: 5
Quote DC0826 Replybullet Posted: 24 Oct 2013 at 8:53am
Thanks... that worked.  Now all of my summary totals are out of whack.  I know have four group levels with this new group.  At each level I need it to subtotal the miles, hrs, ect.  Is there a way to total just the group totals and not the details?  I am getting a subtotal for group three that is substantially higher than if I were to add up the summary totals of group 4.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 24 Oct 2013 at 8:58am
are you talking about fields like "miles driven" and "hours"?
these should not ahcnge for the group so youc an just palce teh field ont eh header or footer to show the value for the group.
if you need to summarize these beyond the group (e.g. report footer) you can use shared variable formula's or Running Totals to calculate that.
Please explain further exaclty what you need.
IP IP Logged
DC0826
Newbie
Newbie
Avatar

Joined: 23 Oct 2013
Online Status: Offline
Posts: 5
Quote DC0826 Replybullet Posted: 24 Oct 2013 at 9:15am
In order to accomplish my original goal I went ahead and took the above suggestion of creating a new group based on route ID to I could get the total of the gallons recorded by route id on table two.  So I moved the route id, miles driven, hours ect up into the header for this new group 4 so it would match up with the gallons collected.  Now for groups 1, 2, and 3 the totals for the miles and hours are way too high.  I think it might be calculating the detail along with the totals calculating in the header in group 4 so it is compounding the value.  Does this make sense?  
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 24 Oct 2013 at 9:26am
correct. a SUM is A sum of all rows (not just displayed).
You can use Running Totals or Shared Variables to get the values you want.
I prefer RT's (most other seem to prefer shared variables).
Especially if you need to display the data on multiple grouping levels I prefer RT's as you can use one per value vs. 3 per value as a shared variable.
 
 
The RT version of MIles for grouplevel 1 is
name=GL1_miles (or whatever)
field to summarize=Miles
evaluate=on change of a group (routeid)
reset= on change of group (select group level 1)
place in Group level 1 footer
Neither a shared variable nor a RT work in a Group header
IP IP Logged
DC0826
Newbie
Newbie
Avatar

Joined: 23 Oct 2013
Online Status: Offline
Posts: 5
Quote DC0826 Replybullet Posted: 26 Oct 2013 at 3:25am
So last question on this and I will close.  First I want to thank you for all of your help. 

So my last issue is that I needed to add a third table that is linked by route id.  Like table 2 above it has all of the stops listed but table three has two values for each stop... Arrival time and departure time.  The total service time is equal to departure time less arrival time.  What I would like to do is sum all of the stops service time on this report so I can compare total route time vs service time.  Since this is a formula I am pretty sure that a summary can not work.  I have added a running total for this formula and I am not getting the correct answer.  Any suggestions?
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 26 Oct 2013 at 4:09am
can you post some sample data?I am unclear if you have one row with two datetime fields or two roww with one datetime fierl and a text field to indicate if it is an open or a close 
IP IP Logged
DC0826
Newbie
Newbie
Avatar

Joined: 23 Oct 2013
Online Status: Offline
Posts: 5
Quote DC0826 Replybullet Posted: 26 Oct 2013 at 4:21am
Table 1
Route ID   Route Date   Driver Name   Miles Driven   Hours on Route
11111       9/30/2013    xxxxxx            1000              50
22222       9/1/2013      bbbbb             200                 6
33333       9/15/2013    cccccc              100                 8
44444       9/10/2013    ddddd              50                  9
 
Table 2
Route ID  Location ID  Gallons Collected
11111             1a                      5
11111             1b                      6
11111             1c                     10
22222             1d                     25
22222             1e                     30
44444             1f                      20
44444             1g                     30

Table 3

Route ID  Location ID  Arrival Time  Departure Time
11111             1a                10:00         10:05
11111             1b                10:30         10:37
11111             1c                 10:40         10:45
33333             2a                9:15            9:30
22222             1d                11:50          11:58
22222             1e                12:05          12:10
44444             1f                 8:30            8:35
44444             1g                8:50            8:55

I want to create a report that shows the following:

Route ID   Route Date   Driver Name   Miles   Hours   GC  Service Time
11111       9/30/2013    xxxxxx            1000    50        21         .28
22222       9/1/2013      bbbbb             200      6         55          .30
33333       9/15/2013    cccccc              100       8          0          .25
44444       9/10/2013    ddddd              50      9          50          .17
IP IP Logged
Page  of 2 Next >>
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