Results 1 to 3 of 3
  1. #1
    Sephaerius is offline Advanced Beginner
    Windows 7 64bit Access 2013 32bit
    Join Date
    Aug 2013
    Posts
    62

    Query expression to simulate vlookup/true


    I'm trying to convert an Excel template over to Access, and in doing so I need to simulate a vlookup/true formula within my query.
    In the column I'm trying to return, I am using the DateDiff() expression to capture the number of days between two dates, which will range from 0 into the thousands. I have joining table that lumps together aging "buckets", which in Excel is done via vlookup/true (closest match). It looks like this:
    AGE ....AGING BUCKET
    0 .........0-30
    31 .......31-60
    61 .......61-90
    91 .......91-120
    121 .....121-150

    And so on, etc.

    Is there a query expression or joining method that will achieve the same result?

    Thanks,

  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    First you will need to create a field in a query that returns the AGING BUCKET and you can use that to join on in a second query. You can do it either with one long IIf statement in the query or use a VBA function (functions can make queries run slower so if you have very many records this should be avoided).

  3. #3
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2007
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Two approaches here

    Either create a table in excel with AgeValue and agegroup then import it into access. Then join this to your table which has the age?


    Or use a function. If created inside a module it can be called from any query
    Code:
    Function Agegroup (agevalue as integer) as string
    Select case agevalue
    Case<31
    Agegroup = "0-30"
    Case 31 to 60
    agegroup   = "31-60"
    case 61 to 90
    agegroup = "61-90"
    case 91-120
    agegroup = "91-120"
    case >121
    agegroup = "121-150" 
    End case
    End function

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

Similar Threads

  1. Replies: 1
    Last Post: 07-14-2015, 05:59 AM
  2. vlookup in a query
    By tomeratz in forum Queries
    Replies: 1
    Last Post: 07-13-2015, 02:21 AM
  3. Replies: 8
    Last Post: 10-06-2014, 03:02 PM
  4. Query to work as a Vlookup function
    By dharmik in forum Queries
    Replies: 21
    Last Post: 01-04-2012, 08:12 AM
  5. Access equiv to the vLookup in a Query
    By Scorpio11 in forum Queries
    Replies: 10
    Last Post: 07-07-2010, 11:36 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