Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Extracting correct data Post Reply Post New Topic
Author Message
NoelO
Newbie
Newbie
Avatar

Joined: 18 Dec 2011
Online Status: Offline
Posts: 3
Quote NoelO Replybullet Topic: Extracting correct data
     Posted: 20 Dec 2011 at 12:10am
I am very much a newbie as far as CR goes.  I am trying to produce a report to show stock variances on fuel tanks and I need help with following:

I have:
    DipTanks.Tank : String[50]
    DipTanks.DipDate : DateTime
    DipTanks.DipAmount : Number
    DipTanks.UniqueID : Number

    FuelPurchasesAllocation.TDate : DateTime
    FuelPurchasesAllocation.Tank : String[50]
    FuelPurchasesAllocation.Allocated : Number

    POSTransactionHistory.TDate : DateTime
    POSTransactionHistory.Type : String[2]
    POSTransactionHistory.Tank : String[50]
    POSTransactionHistory.Quantity : Number

My report needs to look something like this:

DipTanks.Tank e.g. "Tank01"
DATE.  OPENING DIP.  PURCHASES.  SALES.    THEORETICAL CLOSING DIP.
  (a)             (b)                  (c)             (d)                         (e)
ACTUAL CLOSING DIP.
                (f)

(a) = Date({DipTanks.DipDate})
(b) = DipTanks.DipAmount
(c) = FuelPurchasesAllocation.Allocated WHERE FuelPurchasesAllocation.Tank = DipTanks.Tank AND Date({FuelPurchasesAllocation.TDate}) = Date({DipTanks.DipDate})
(d) = SUM(POSTransactionHistory.Quantity) WHERE POSTransactionHistory.Tank = DipTanks.Tank AND
POSTransactionHistory.TDate BETWEEN DipTanks.DipDate AND DipTanks.DipDate [Next day]
(e) = (b)+(c)-(d)
(f) = OPENING DIP for the next record.

How can I join Diptanks.Dipdate and FuelPurchasesAllocation.TDate based on the Date element only, or should I use a subreport?

How can I select the sum of the Quantity from the DipDate to the next Dipdate (following day)?

Also the Actual Closing Dip is the Opening Dip for the next day, how do I extract that?

Hope that makes sense and that someone can give me some pointers in the right direction.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 20 Dec 2011 at 6:50am
one would think that you would join diptanks and fuelPurchaseAllocation on date alone I would think that you would have more than 1 dipTank.
 
depending on how the report should read, i would think that you would link all the records together on Tank and then you could group by tank, and order by the TDate.
 
Shared variables will allow you to make the close of one day the open value of the next.  You can use NEXT() and/or PREVIOUS() to find differences...but be careful, CR will do what you tell it, and it will cross group.  You could also use shared variables for this as well, and/or Running Totals, though that is nto my forte.
 
Shared variables typically are used in 3 formula combinations
1) reset (typically a group header): 
shared numbervar a :=0;
 
2)display (typically a group footer):
shared numbervar a;
a
 
3)increment (typically details):
shared numbervar a;
 
if {table.field1} = 1 then a := a + {table.field2};  //any condition and action
 
HTH
IP IP Logged
NoelO
Newbie
Newbie
Avatar

Joined: 18 Dec 2011
Online Status: Offline
Posts: 3
Quote NoelO Replybullet Posted: 22 Dec 2011 at 12:30am
Thank you for the response, however I am still not clear on the linking of the tables DipTanks and FuelPurchasesAllocation.  Maybe I should clarify.  Yes there are multiple tanks (5).  Dips of the tanks are taken each day at about 06:30 and the date + time are recorded in DipTanks.DipDate.  Purchases are made on some days but not every day.  The date + time of purchase are recorded in FuelPurchasesAllocation.TDate. The time element of TDate will not match the time element of DipDate, hence my question about linking.

The following example should help:

TABLE : DipTanks
Tank         DipDate                      DipAmount    UniqueID
Tank01    15/12/2011 06:30:20    1,000        201    
Tank02    15/12/2011 06:30:20    5,000        202
Tank01    16/12/2011 06:30:00    6,000        203    
Tank02    16/12/2011 06:30:00    3,000        204
Tank01    17/12/2011 06:30:15    500           205    
Tank02    17/12/2011 06:30:15    9,000        206
Tank01    18/12/2011 06:30:00    7,500        207    
Tank02    18/12/2011 06:30:00    5,000        208

TABLE : FuelPurchasesAllocation
TDate            Tank    Allocated
15/12/2011 10:15:00    Tank01    8,000
15/12/2011 10:15:00    Tank02    4,000
17/12/2011 13:20:00    Tank01    7,500
17/12/2011 13:20:00    Tank02    9,000

From the above tables I require the following partial sample report:


Tank01
DATE        DIP    PURCHASES
15/12/2011    1,000    8,000
16/12/2011    6,000    0
17/12/2011       500    7,500
18/12/2011    7,500    0

As I said, I am very much a newbie at this and I am confused as to whether I should link the tables, but if I do, how do I link on the date element only of DipDate and TDate? Or do I use a subreport, but then how do I reflect zero for the days when there are no purchases?  

IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 23 Dec 2011 at 3:19am
ok, I think I see what you want.
 
I think that you will want to link on the name of the tank, as the date won't work...CR will see the dates as different.
 
what you can do, is group by the date.  You can create a formula that you can group on, and it can be as simple as this:
totext({table.dateField}, "dd/MM/yyyy")
 
when you create the group, just select your formula as the source instead of a table.field combination.
 
you can use the formula to psuedo link.
 
As for missing days, that is harder as CR will only print what it sees.  if you have a table of dates, you could outer join to that so that all dates would be represented...or maybe you could your dip dates..if there is recording for each day irrespective of purchase.
 
For data like this, ok...any report, I am a big proponent of store procs.  They allow for data manipulation and customization of the data in ways that CR has a difficult time managing.  Using this report as an example, you could transform the dip date time to a consistent datetime so that all the data would link up...for that matter you could create a line for each date, record the dip measurement and if a purchase was made, and it would all be in one line.  If missing days occurred, you might be able to fill in the missing the date by joining to a table of dates or figuring out a way to 'create' the missing days.
 
HTH
IP IP Logged
NoelO
Newbie
Newbie
Avatar

Joined: 18 Dec 2011
Online Status: Offline
Posts: 3
Quote NoelO Replybullet Posted: 23 Dec 2011 at 7:58am
Thanks, you have given me some ideas to think about and work on.
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