Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Bosnjanac is offline Novice
    Windows 8 Access 2013
    Join Date
    May 2015
    Posts
    8

    Problem with km

    Hi all,

    I am first time on forum and I say hello to all. I am glad to be member of this forum.

    I make one table for Fuel statistics for my friend. After I import data from Excel I get one problem.

    Click image for larger version. 

Name:	Capture.PNG 
Views:	21 
Size:	2.1 KB 
ID:	20616


    Here is problem. I have query which have to fields with data for km. One field should be Max millage for past mounth, and other field should be Max millage for this month. How can I set this in query? Millage is in same table like other relevant data for fuel statistics.

    Thanks

  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
    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
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    You need the criteria to limit the date range to 1 month.

  4. #4
    Bosnjanac is offline Novice
    Windows 8 Access 2013
    Join Date
    May 2015
    Posts
    8
    Yes, i mean milage. When I enter citeria in Query Design I get this error:

    Click image for larger version. 

Name:	Capture.PNG 
Views:	15 
Size:	8.5 KB 
ID:	20620

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    That criteria is text. Is km field a date/time type?

    Review http://allenbrowne.com/ser-36.html
    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.

  6. #6
    Bosnjanac is offline Novice
    Windows 8 Access 2013
    Join Date
    May 2015
    Posts
    8
    I confuse you and myself. Is there any way to use Where Clause in Max(table.field) AS Max. I need to find Max value for millage for certain month.

  7. #7
    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:

    SELECT Year([date field]) & Month([date field]) AS YrMo, Max([field name]) AS MaxSomething FROM tablename GROUP BY Year([date field]) & Month([date field]);
    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.

  8. #8
    Bosnjanac is offline Novice
    Windows 8 Access 2013
    Join Date
    May 2015
    Posts
    8
    Thanks, just to ask can I into Max([field name]) AS MaxSomething add where clause?

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Criteria for what field? Under the constructed YrMo field can have: "201501"
    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.

  10. #10
    Bosnjanac is offline Novice
    Windows 8 Access 2013
    Join Date
    May 2015
    Posts
    8
    I stuck here. I must to find Max milage for venchile for this mounth and take away max milage for venchile for past mounth.
    Click image for larger version. 

Name:	Capture.PNG 
Views:	8 
Size:	2.8 KB 
ID:	20648

    In field Prosli:km I need to show max millage to find Max milage for February 2015 (Feb-15). Field km from table evidencija show max milage for mounth "Mar-15".

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    That usually requires a nested subquery. Review link referenced back in post 2.
    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.

  12. #12
    Bosnjanac is offline Novice
    Windows 8 Access 2013
    Join Date
    May 2015
    Posts
    8
    Hmm, I am stuck here. Is there any way to share my db with you and help me with it?

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    Can attach file to post. Follow instructions at bottom of my post.
    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.

  14. #14
    Bosnjanac is offline Novice
    Windows 8 Access 2013
    Join Date
    May 2015
    Posts
    8
    I attach you database. In db is only query there is two fields with km value from fuel. First it should be Max km from past mount, and second should be Max km from last mount. There is no date and time for mounts, only values Jan-15, Feb-15, Mar-15.

    Thanks for help.
    Attached Files Attached Files

  15. #15
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,626
    The [mount] data is not a date/time type. This really complicates sorting process. Build a query that returns a YrMo value. I modified Main to:

    SELECT fuel.*, cars.registration, Left([mount],3) AS Mo, Right([mount],2) & "-" & Switch([Mo]="Jan","01",[Mo]="Feb","02",[Mo]="Mar","03",[Mo]="Apr","04",[Mo]="May","05",[Mo]="Jun","06",[Mo]="Jul","07",[Mo]="Aug","08",[Mo]="Sep","09",[Mo]="Oct","10",[Mo]="Nov","11",[Mo]="Dec","12") AS YrMo
    FROM cars LEFT JOIN fuel ON cars.[card] = fuel.[card];

    Now use that query like a table in other queries.

    Each card has multiple records for each mount and this is causing complication. Really needed the day part of dates, not just month and year.

    Maybe this is what you want:

    SELECT Main.ID, Main.Registration, Main.card, Main.YrMo, Main.km, (SELECT TOP 1 Dupe.km
    FROM Main AS Dupe
    WHERE Dupe.Card = Main.Card AND Dupe.ID<Main.ID
    ORDER BY Dupe.Card, Dupe.ID DESC) AS PriorValue
    FROM Main
    ORDER BY Card, Main.ID;

    Unfortunately it relies on linking and sorting by the ID field. This means the ID must always be increasing when records are entered and also that records are entered in an order that the km is always increasing.


    Why is [station] field in both tables? What is [sum] field for?
    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.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 10-31-2012, 11:52 AM
  2. Replies: 2
    Last Post: 06-14-2010, 03:25 PM
  3. query problem i have a problem wi
    By maxx3 in forum Queries
    Replies: 0
    Last Post: 06-29-2009, 02:29 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