Results 1 to 3 of 3
  1. #1
    nagiese is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jan 2011
    Location
    Nashville, TN
    Posts
    43

    How do you right a formula in a query to reference the data in a previous row for a column

    I am recreating a series of queries and reports in access, the original is in a system called Brio (and old querying tool by Oracle now owned by IBM, I believe). We are moving away from Brio but have no working tool. Thus we have decided to re-wright this in MS Access. I've run into some issues where there are formulas in the results from a query that reference the previous row instance of a record. I'm not sure how to rewrite a formula like this in MS Access. The Brio formula looks like this:


    Code:
     if ( Base_Lot == Prior (Base_Lot) && Selling_Sector == Prior (Selling_Sector) && Acct == Prior (Acct)  && Description == Prior (Description)) { 'Drop' }
    They have used the Prior function in Brio to reference the previous instance of that item in the previous row. I would really appreciate it if someone would please tell me how re-wright this in an MS Access query. So lost on this one.

    Thanks for all your help.

  2. #2
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Unfortunately, a query in MS Access cannot do that - there is no function similar to "Prior". Queries and recordsets can refer only to fields in the current record, and know nothing about other records in the query or recordset. And this makes sense - because a query can so easily be re-ordered a "prior" function would be meaningless, since its value would be totally dependant on the ordering.

    You are probably going to have to use VBA and a recordset to achieve what you want.

  3. #3
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    there is no equivalent to Prior in Access.

    databases have no sense of previous/next/first/last without some sense of order (a date/time of input or PO number for example). To do this in Access you would typically use a subquery. However there is not enough information provided to suggest what that subquery might look like - there are different ways depending outcomes required.

    Suggest post the structure of your table, some sample data and what your expected outcome would be from that sample data.

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

Similar Threads

  1. Replies: 3
    Last Post: 07-15-2015, 12:01 PM
  2. Replies: 4
    Last Post: 09-04-2013, 06:40 AM
  3. Replies: 2
    Last Post: 09-26-2012, 04:22 AM
  4. Query to use previous row's data ?
    By amrut in forum Queries
    Replies: 1
    Last Post: 07-25-2012, 06:20 AM
  5. Replies: 1
    Last Post: 06-18-2011, 10:00 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