Results 1 to 3 of 3
  1. #1
    crimedog is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2013
    Posts
    141

    Run a query that gives last entry prior to date

    there are multiple reps that can have quota changes throughout the year - I need a query that returns the latest quota change prior to a specific date
    I have attached a Database - See QuryQuota1
    There should be 3 results Rep 1 Quota - Rep 2 Quota - Rep 3 quota



    It is returning 4 results (2 quotas for rep 1 ) because I am asking for the last quota change before or equal to January
    Attached Files Attached Files

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Maybe TOP N will accomplish. Review http://allenbrowne.com/subquery-01.html#TopN
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    create this query

    Code:
    SELECT TblQuota.RepID, Max(TblQuota.DateOfChange) AS MRChange
    FROM TblQuota
    GROUP BY TblQuota.RepID;
    Save it as qryMRChange


    Create this query

    Code:
    SELECT TblQuota.ID, qryMRChange.RepID, qryMRChange.MRChange, TblQuota.Quota
    FROM qryMRChange LEFT JOIN TblQuota ON (qryMRChange.MRChange = TblQuota.DateOfChange) AND (qryMRChange.RepID = TblQuota.RepID)
    GROUP BY TblQuota.ID, qryMRChange.RepID, qryMRChange.MRChange, TblQuota.Quota;
    Should give you the most recent quota record for your reps

    This is making use of an AGGREGATE query to find the most recent date (this assumes there is 1 and only 1 record per rep per day) then links that back to the quota table to get the specific information (quota volume)

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

Similar Threads

  1. Replies: 1
    Last Post: 03-23-2015, 09:42 AM
  2. Replies: 20
    Last Post: 01-13-2015, 02:23 PM
  3. Replies: 1
    Last Post: 09-06-2014, 01:08 PM
  4. Add one day to prior record's date/ how??
    By mkfloque in forum Access
    Replies: 3
    Last Post: 05-30-2012, 04:44 AM
  5. Date Parameter Help - prior 13 weeks
    By acw1980 in forum Access
    Replies: 1
    Last Post: 11-12-2009, 10:30 AM

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