+ Reply to Thread
Results 1 to 2 of 2

Lookup on Date Periods - with another reference

  1. #1
    Registered User
    Join Date
    01-03-2005
    Posts
    35

    Lookup on Date Periods - with another reference

    I have a list of date periods, which references a particular item. So each item will have one or more periods associated with it. So in the example below, I've concatanated the Item and Period No to give a unique reference for each (UK Dates used in this example):

    PERIODS

    Item----Period----PeriodRef----Start-----End
    A-------1---------A-1----------01/01/09--15/01/09
    B-------1---------B-1----------01/01/09--09/01/09
    C-------1---------C-1----------05/01/09--12/01/09
    C-------2---------C-2----------15/01/09--20/01/09


    I then have a list of orders, which I receive from another source, which reference the item no and the date, e.g.:

    ORDERS

    Item----OrderDate----Quantity
    A-------03/01/09-----3
    A-------10/01/09-----5
    A-------20/01/09-----4
    B-------07/01/09-----7
    C-------01/01/09-----2
    C-------11/01/09-----6
    C-------17/01/09-----5
    C-------22/01/09-----4


    What I want to do is to compare these orders to the periods in the original table to:
    - list/summarise orders which were in each period
    - list/summarise orders which were outside of a valid period

    So in the example above, I'd like to see:

    COMPARISON-CALCULATION

    Item----OrderDate----Quantity----PeriodRef----InPeriod?
    A-------03/01/09-----3-----------A-1----------Y
    A-------10/01/09-----5-----------A-1----------Y
    A-------20/01/09-----4-----------A-1----------N
    B-------07/01/09-----7-----------B-1----------Y
    C-------01/01/09-----2-----------C-1----------N
    C-------11/01/09-----6-----------C-1----------Y
    C-------17/01/09-----5-----------C-2----------Y
    C-------22/01/09-----4-----------C-2----------N


    In order to produce a final summary as follows, where QntyInPeriod is the quantity of orders which were within a Period for that Item and QntyOutPeriod is the quantity for orders which were not inside one of the periods for that item


    PeriodRef----Start-------End-------QntyInPeriod----QntyOutPeriod
    A-1----------01/01/09----15/01/09--8---------------4
    B-1----------01/01/09----09/01/09--7---------------0
    C-1----------05/01/09----12/01/09--6---------------2
    C-2----------15/01/09----20/01/09--5---------------4



    So my original approach was to :
    - concatonate the Item no and Order Date in the ORDERS table
    - concatonate the Item no and start date in the PERIODS table
    - Lookup the first of these values against the second with a 'TRUE'on the RangeLookup in order to find the nearest value from PERIODS rather than the exact value. This would compare each order to a PeriodRef
    - Compare the order date to the start date of the PeriodRef returned to see if it was within the period date or not

    This would have worked fine, if it wasn't for the fact that I only want to compare each order against periods related to the item in question. So in the example above, the row from the ORDERS table:

    Item----OrderDate----Quantity
    C-------01/01/09-----2


    Returns B-1 from the PERIODS table.

    Does anyone have any ideas as to how I might overcome this?

    Thanks in advance for your help!!
    Last edited by grey; 07-14-2009 at 06:27 AM. Reason: Note on formatting

  2. #2
    Registered User
    Join Date
    01-03-2005
    Posts
    35

    Re: Lookup on Date Periods - with another reference

    Sorry about the original formatting on this post - it should hopefully be readable now!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1