Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: date selection puzzle Post Reply Post New Topic
Author Message
IanShorrock
Newbie
Newbie


Joined: 25 Jan 2008
Location: United Kingdom
Online Status: Offline
Posts: 9
Quote IanShorrock Replybullet Topic: date selection puzzle
     Posted: 24 Sep 2010 at 5:32am
Hi - I hope someone can help with a problems thats been puzzling me for some time.

I have a table which holds a list of customers, the items they buy, the price they pay, and the date at which that price becomes effective. The table will hold past prices and effective dates and also those in the future still to come into effect. Customers can take the same items but may have different prices and effective dates.

The price will change when the next effective date comes into force. If there is not a new date then the price at the last effective date stays in force.


Customer   item      price       date
1               abc       10        Jan 2009
1               abc       20        Jan 2010
1               abc       30        Jan 2011
2               abc       15        Jan 2009
2               xyz       5          Jan 2009
2               xyz       7          Jan 2010
2               xyz       9          Jan 2011

For each customer / item combination I need to be able to determine which is the the current effective price, EG the price at 24 Sept 10 for abc would be 20 for Cust1 and 15 for Cust 2. xyz would be 7 for cust 2.

I need to be able to extract the current effective price as I need to display it in another report via a subreport.

I have tried various formualae, datediffs, max dates etc but none work 100%.

Any help much appreciated

Ian S
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 24 Sep 2010 at 10:44am
does your items price table have a begin and end date?
if so use a join on ID and date fields where sales table date is between item price dates
IP IP Logged
IanShorrock
Newbie
Newbie


Joined: 25 Jan 2008
Location: United Kingdom
Online Status: Offline
Posts: 9
Quote IanShorrock Replybullet Posted: 26 Sep 2010 at 10:56pm
Hi - thanks for your reply

Sorry no, there are not beginning and end date fields as such, just one field - an effective date - the date the new price starts to be used.   
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 27 Sep 2010 at 4:10am

Are all of your effective dates annual changes, meaning the year is unique per pricing?

IP IP Logged
IanShorrock
Newbie
Newbie


Joined: 25 Jan 2008
Location: United Kingdom
Online Status: Offline
Posts: 9
Quote IanShorrock Replybullet Posted: 27 Sep 2010 at 4:23am
Unfortunately no !

An effective date can last for any time period, a day, a month, ten years. An effective date only ends when a new date is entered onto the table and that date becomes due.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 27 Sep 2010 at 4:41am

only thing that is coming to mind is doing a double join

iD=ID
effectivedate<=orderdate
Use grouping and a Running Total that evaluates using a MAX(date) to get the highest value
 
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