Results 1 to 6 of 6
  1. #1
    jamesborne is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Dec 2011
    Posts
    13

    Finding the difference between the dates of two records

    Dear Access buddies,



    I have a query consisting of the following:
    -Date
    -Customer
    -OrderAmount

    I am trying to have another field called "average days between order". This field should basically find the difference between each customer's orderdates.
    i.e the difference in days between the last order date and the one before (for each customer).

    To make things clearer:
    1. Find the difference between the dates of order [X] and order [X+1] from each customer.

    Thanks in advance,
    James Borne

  2. #2
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    The previous order and the one before that - will be on two different rows in the Table - right?

  3. #3
    jamesborne is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Dec 2011
    Posts
    13
    Robeen, that's correct.

  4. #4
    Robeen is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Mar 2011
    Location
    Tulsa, Oklahoma.
    Posts
    1,596
    Google 'Top N Values per Group Query'.

    What this lets you do is isolate one [or more] record per customer - depending on how you sort the records.

    Also . . .

    You can also look at this query example [that I haven't tested] to pull the second highest value per CustomerID.

    select CustomerID
    , max(Amount) as SecondMaxAmount
    from Sales S
    where Amount <
    ( select max(AMount)
    from Sales
    where CustomerID = S.CustomerID )
    group
    by CustomerID


    You will have to play with these two methods.

    What I would do is create a query that gives you the Max(DateField) and then another query that gives you the SecondMax [like example above].
    Now create a third query that uses the data from both these queries and you will get the Max for each Customer from the first query and the SecondMax for each Costomer from the second query - and bot of them will be in the same row of data [join the CustomerID fields in the two queries in design view].
    Then - in your third query - you can create a new field that uses the 'DateDiff()' function to find the difference between the two dates.

  5. #5
    jamesborne is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Dec 2011
    Posts
    13
    Quite frankly, you're not helping at all. Let me be make it easier:

    I have 2 fields.
    A: Date
    B: Customer

    Now I want to create a third field [datedifference], that will have the difference between the dates for each customer. Do you get that?
    Example:
    ID Date Customer DateDifference
    1 1/1/2012 Einstein --
    2 3/1/2012 Davinci --
    3 5/1/2012 Einstein 4
    4 9/1/2012 Davinci 6


    Thanks for your help in advance,
    James Borne

  6. #6
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quite frankly, James, you're being rude. Robeen was trying to be helpful. Maybe he misunderstood, but he was still trying. Maybe your explanation was unintelligible??

    It sounds like what you want to do is akin to calculating gas milage. Here are 3 sites to check out:

    http://www.rogersaccesslibrary.com/forum/topic445.html

    http://www.rogersaccesslibrary.com/forum/topic516.html

    http://bytes.com/topic/access/answer...lc-gas-mileage

    http://www.utteraccess.com/forum/Gas...-t1211144.html


    Good luck

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 10
    Last Post: 12-27-2011, 01:20 PM
  2. Replies: 3
    Last Post: 07-05-2011, 02:25 PM
  3. Finding Records that are not there!
    By TrudyD1474 in forum Queries
    Replies: 2
    Last Post: 06-18-2010, 04:41 PM
  4. finding records in a database....
    By softspoken in forum Forms
    Replies: 1
    Last Post: 04-23-2010, 11:17 PM
  5. Count difference between two dates
    By Costa in forum Forms
    Replies: 3
    Last Post: 03-09-2010, 10:38 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums