Results 1 to 5 of 5
  1. #1
    mark6455 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2021
    Posts
    10

    Need help with formula

    I need some help with a formula please.


    I have a database that I store every detail of my vehicle expenses in. I wrote it, but it was years ago and I forgot a lot of the methods. What I need is the following.

    I have a category called 'REGENS'. For those that do not know, I have a diesel engine which goes into a mode called regeneration every so many miles. I track the start and end of each regen.

    I need to take the latest regen odometer miles that occurs and find the previous regen that occurred mileage and then subtract the difference to get a field that shows how many miles it was between each regeneration.

    So, I need to use the previous regen END mileage, subtract it from the new regen START miles and get a number.

    In my database, start mileage is called "START MILEAGE" and ending mileage is called "ENDING MILEAGE" on each record. I flag that the entry that indicates a regen by having a checkbox to indicate this entry is a regen cycle. I am trying to figure out when the checkbox (called LABEL84) is checked that I want the previous regen end mileage to subtract from the new entry's start mileage and show that number.

    Any guidance appreciated. Thanks

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,555
    Your memory is worse than mine.
    https://www.accessforums.net/showthr...384#post482384

    And best not to name a checkbox label anything.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    mark6455 is offline Novice
    Windows 10 Access 2016
    Join Date
    Sep 2021
    Posts
    10
    I was so busy with work, I didn't have time back then. LOL. I am retired now so I have time. But now because of an issue with Nissan, I need the data. Too time consuming for manual calcs on 174 regens.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    In Access, this calls for a correlated subquery. Review http://allenbrowne.com/subquery-01.html#AnotherRecord

    Other database platforms have special functions to accomplish this.
    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.

  5. #5
    DavidW2 is offline Novice
    Windows 10 Access 2013 64bit
    Join Date
    Apr 2025
    Posts
    1
    You’ll need to query entries where LABEL84 is checked (indicating a regen), then sort by date or mileage. For each new regen, subtract the previous record’s ENDING MILEAGE from the current START MILEAGE. In Excel, use =A2 - OFFSET(B2,-1,0) assuming A2 is START MILEAGE and B2 is ENDING MILEAGE. In a database, use a self-join or window function like LAG() to access the previous row.

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

Similar Threads

  1. Replies: 19
    Last Post: 07-13-2015, 10:15 AM
  2. Replies: 41
    Last Post: 05-29-2015, 02:58 PM
  3. Need help with builder formula
    By shantmov in forum Access
    Replies: 2
    Last Post: 11-11-2012, 04:09 AM
  4. Need help creating a formula
    By Jimmy0291 in forum Queries
    Replies: 1
    Last Post: 01-17-2011, 12:12 PM
  5. Need help with Query formula
    By krymer in forum Queries
    Replies: 5
    Last Post: 09-30-2010, 06:51 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