Results 1 to 4 of 4
  1. #1
    316854 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Mar 2013
    Posts
    44

    Fuel Efficiency

    Access newbie. Access 2013.

    Please see attached database.



    How do I add a calculated field for miles per gallons?
    Attached Files Attached Files

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Your Miles data is cumulative which means you need the difference between sequential records. Not easy, need subquery. Review http://allenbrowne.com/subquery-01.html#AnotherRecord

    Should not use spaces, special characters/punctuation (underscore is exception) in names, nor reserved words as names. The $ and Date as field names is a bad idea.
    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
    316854 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Mar 2013
    Posts
    44
    The more I pull my hair out trying to use Access for calculations the more it makes me think that I should be using Excel for this kind of stuff. It seems like, regarding calculations, what would take me 30 seconds to set up in excel takes 5 minutes in Access, possibly even needing VBA.

    Many times I wonder why I'm trying to leave Excel for Access.

    I need encouragement.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,931
    Excel is a better tool for mathematical analysis but very poor database manager. Sometimes like using a hammer to do a screwdriver task. You might get it to work but could be frustrating experience. Access can be made to do the calcs but can be harder than Excel. The data must be properly defined.

    I took another look at your data. The subquery won't work because there are no identifiers like the MeterID and AddressID in Allen Browne's example.

    An alternate approach requires a sequential ID without gaps. Your autonumber is not without gaps. If the dates did not have gaps, that field could serve as the sequential ID.

    Here is one that doesn't require any unique ID:
    SELECT MPG.*, ([Miles]-DMax("Miles","MPG","[Date]<#" & [Date] & "#"))/[Gal] AS M_P_G FROM MPG;

    However dates cannot be duplicated unless there is other criteria to filter with, such as a vehicleID.
    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.

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

Similar Threads

  1. vehicle fuel consuption
    By Daniel2000 in forum Queries
    Replies: 14
    Last Post: 08-30-2013, 06:05 AM
  2. fuel consuption database
    By Daniel2000 in forum Programming
    Replies: 6
    Last Post: 08-16-2013, 01:27 AM
  3. Crosstab Efficiency
    By kwooten in forum Queries
    Replies: 2
    Last Post: 06-13-2012, 12:21 PM
  4. Lotsa code; need help with efficiency!!
    By usmcgrunt in forum Forms
    Replies: 5
    Last Post: 08-26-2011, 07:49 AM
  5. Query efficiency
    By cheshire_smile in forum Queries
    Replies: 1
    Last Post: 07-01-2011, 09:24 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