Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: history based on transaction date Post Reply Post New Topic
Author Message
smileymahoney
Newbie
Newbie
Avatar

Joined: 09 Jan 2008
Online Status: Offline
Posts: 5
Quote smileymahoney Replybullet Topic: history based on transaction date
     Posted: 09 Jan 2008 at 1:59pm

I’m fairly new to Crystal, and using version 8.5.0.217.  All learning has been on my own and using “Crystal Reports: A Beginner’s Guide” by David McAmis.  I’m trying to write a report that I think is possible, but am not sure where to begin. 

 

My first question is to get advice on whether or not the below is possible.  If it is, suggestions of how to approach & recommended formulas are appreciated.

 

I am trying to create historical monthly (or weekly) data from a transaction table.  Fields available:

1.       Item

2.       Date of transaction

3.       Time of transaction

4.       Inventory on hand at the date & time of the transaction

 

What I’d like to do:

a.       Create separate fields for the last 16 months.  Eg… current month = m, last month = m-1, etc…  (I do know how to create a new formula field… the problem is in how to write the formula that goes into it)

b.      Current month would show the inventory on hand, for each distinct item, with the most recent transaction date and time, within the current month.  If no transactions happened for the given part in the current month, then take inventory on hand for the most recent date and time.

c.       Last month (m-1) = show the inventory on hand, for each distinct item, with the most recent transaction date and time, within month (m-1).  If no transactions happened for the given part in the given month, then take inventory on hand for the most recent date and time.

d.      Continue on for x months of history

 

Hope that made sense.  Any insights are appreciated.

 
One last question.... knowing that I'm in an old version of Crystal, is there still enough benefit to justify  buying the encyclopedia, or are there other books that you would recommend?  I do enough Crystal reporting that the beginners book I have is too basic. 
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 09 Jan 2008 at 2:37pm
Let me see if I have this straight, you want to loop through the records create a history for the past 16 months. If the part has 16 months of data, then each formula would have a value. If the part only had 3 months of data, then formulas m through m-2 would have data and the rest would be zero. Then you want to display a single line with all this historical data for the part?

Is this a correct interpretation?

Re the book, the Encyclopedia should be good for you. It is 90% general CR reporting tasks and I would say around 10% applies to CR XI specific information. CR doesn't really change much from version to version.
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
smileymahoney
Newbie
Newbie
Avatar

Joined: 09 Jan 2008
Online Status: Offline
Posts: 5
Quote smileymahoney Replybullet Posted: 09 Jan 2008 at 2:45pm

Basically yes.

Example to clarify a little bit... if the part only had 3 months of data, but it was OLD data in m-6, m-9, and m-12), then the result would show (all on the same row):

part #1

m-1 = 50, m-2=50, m-3=50, m-4 = 50, m-5 =50, m-6=50, m-7=22, m-8=22, m-9=22, m-10=345, m-11=345, m-12=345, m-13=0, m-14=0, m-15=0, m-16=0.
 
Let me know if that's still not clear. 
 
Thanks for the advice on the book... I'm going to order it now.
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 09 Jan 2008 at 3:04pm
Ok, but just to clarify, in the first post you said

"if the part only had 3 months of data, then formulas m through m-2 would have data and the rest would be zero"

but then in the next post you say
"if the part only had 3 months of data, but it was OLD data in m-6, m-9, and m-12"

My confusion is that if the months are all spread apart, do you want them all to appear consecutively starting at m-1, m-2, etc. or should the data match the month that it appears in (m-1 and then maybe m-5 and then maybe m-12). Thus, will the formulas have zeros between the data that correlate to the months with missing data, or do you just want to fill in the first three formulas with historical data and then zero out the remaining 13 months. I hope that is clear.

Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
smileymahoney
Newbie
Newbie
Avatar

Joined: 09 Jan 2008
Online Status: Offline
Posts: 5
Quote smileymahoney Replybullet Posted: 09 Jan 2008 at 3:24pm
Sorry for the confusion.... I think I misspoke in my initial post.
 
If the months are all spread apart I DO want them all to appear consecutively starting at m-1,m-2, etc..  Your understanding is almost correct.  For months that have no new transaction data, the value from the previous consecutive (older) month should carry over.  Example:
 
If the earliest date in the dataset is a 0, then it would carryover until a new transaction was made increasing it (for example) to 5.  Then the value would stay 5 (possibly over many months), until a new transaction was made changing it to 400 (or whatever), etc....
 
Hope that helped...
IP IP Logged
smileymahoney
Newbie
Newbie
Avatar

Joined: 09 Jan 2008
Online Status: Offline
Posts: 5
Quote smileymahoney Replybullet Posted: 09 Jan 2008 at 3:48pm

The end result should look like something I would normally create using a crosstab, with item#'s down the side, and months across the top.  Values would be a snapshot of inventory quantity for the given months.

IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 09 Jan 2008 at 4:10pm
Gotcha. Well, I'm going to write this off the top of my head so you will have to tweak/debug it. If you understand the general idea then you should be able to work it out...

First off, you need to group by Item. This will let you put formulas in the group header and footer.

Next you need a formula which declares the global variables and zeros them out. Something like
Global NumberVar m1:=0;
Global NumberVar m2:=0;
etc.

Put this formula in the Group Header. Now, every time a new item is ready to print, all the variable will be reset.

Now for the tricky part. You need to store the historical data for each month in the appropriate variable. I would do this by finding out how many months are between the today and the current record's month. Then use the result to store to figure out which variable to store the value in.
Global NumberVar m1;
Global NumberVar m2;
....

NumberVar NumMonths;
NumMonths = DateDiff(CurrentDate, {yourtable.yourtransactionfield}, "M");
Select NumMonths
    Case 0:
        m1 := {yourtable.yourinventoryonhand}
    Case 1:
       m2 := {yourtable.yourinventoryonhand}
    ....
    Case 15:
       m16 = {yourtable.yourinventoryonhand};;

Put this in the Details section. Everytime a record is ready is going to print, the appropriate variable will be populated.
You also need to Suppress the Details section because you don't want to see all that data as it's being calculated.
Once you get to the group footer, all the variables will have their data popluated. So create a formula that simply outputs each variable. One formula per variable.
Global NumberVar m1;
m1;

Global NumberVar m2;
m2;

etc.
Put each one of these formulas in the Group Footer. When the report runs, the Details section will do the work of calculating where the on hand numbers belong and the group footer will display them.

Give that a whirl and see what you come up with!

Brian
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
smileymahoney
Newbie
Newbie
Avatar

Joined: 09 Jan 2008
Online Status: Offline
Posts: 5
Quote smileymahoney Replybullet Posted: 10 Jan 2008 at 7:54am
thanks!  I'll give it a shot and let you know how it comes out.
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