Results 1 to 13 of 13
  1. #1
    gtsolid is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2020
    Posts
    19

    Ascending Date order

    Good morning,
    I selected and organized some data from a table, and now i'd like to sort them in a chronological way.
    If I use
    Code:
    ORDER BY Format([Data],"yy/mm");
    I will get this: Click image for larger version. 

Name:	Screenshot 2022-02-23 115825.jpg 
Views:	41 
Size:	9.1 KB 
ID:	47311 January of each year is prompted.
    Is it possible to sort them in the correct way?

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Create a hidden column for both the year and the month and sort on those columns.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    gtsolid is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2020
    Posts
    19
    The table has too many records to be modified now: Click image for larger version. 

Name:	Screenshot 2022-02-23 125210.jpg 
Views:	46 
Size:	18.1 KB 
ID:	47312
    Do you mean this? to add hidden columns in the table or in the query? in the latter case I don't understand

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 10 Access 2016
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,614
    Quote Originally Posted by gtsolid View Post
    The table has too many records to be modified now:
    Do you mean this? to add hidden columns in the table or in the query? in the latter case I don't understand
    No. I was talking about sorting the records from within a query.
    If the field that you want to sort by has a DataType of Date/Time then you would be able to select either Ascending or Descending in the Sort Row of that field when the query is in Design View
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  5. #5
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    Quote Originally Posted by gtsolid View Post
    The table has too many records to be modified now: Click image for larger version. 

Name:	Screenshot 2022-02-23 125210.jpg 
Views:	46 
Size:	18.1 KB 
ID:	47312
    Do you mean this? to add hidden columns in the table or in the query? in the latter case I don't understand
    As an aside, Data and In are reserved words and should not be used as field names

    http://allenbrowne.com/AppIssueBadWord.html#D
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  6. #6
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    would be helpful to see the full sql to your query and some example data since what you have tried should have worked (i.e. assuming data is a date datatype) but what you are showing is another field displayed as mm-yy or perhaps mm-dd

  7. #7
    gtsolid is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2020
    Posts
    19
    That's the full SQL
    Code:
    SELECT Format([Data],"mm/yy") AS Mese, Sum(IIf([In]=0,([Importo]),0)) AS totUscite, Sum(IIf([In]=-1,([Importo]),0)) AS totEntrate, Format$(Abs([totUScite]/[totEntrate]-1),"0%") AS [Risparmiato%], ([totEntrate]-[totUScite]) AS Risparmiato, Round(([totUScite]/31),0) AS [€/gg]FROM Movimenti
    GROUP BY Format([Data],"mm/yy"), Format([Data],"yy/mm")
    ORDER BY Format([Data],"yy/mm");

  8. #8
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    and some example data from Movimenti?

  9. #9
    gtsolid is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2020
    Posts
    19
    Quote Originally Posted by Ajax View Post
    and some example data from Movimenti?
    Click image for larger version. 

Name:	Screenshot 2022-02-28 074427.jpg 
Views:	23 
Size:	36.3 KB 
ID:	47346
    Here it is

  10. #10
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    please provide data in a format that can be copied into a table (excel will do)- remove columns not required.

  11. #11
    gtsolid is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2020
    Posts
    19
    Here it is Movimenti.zip

  12. #12
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    your query per post#7 and data provided works for me
    Mese
    12/15
    01/16
    02/16

  13. #13
    gtsolid is offline Novice
    Windows 10 Access 2016
    Join Date
    Nov 2020
    Posts
    19
    I use "Remove sort" button and worked also for me... What a shame! thanks!

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

Similar Threads

  1. Replies: 3
    Last Post: 12-22-2021, 08:38 PM
  2. Replies: 5
    Last Post: 08-27-2019, 08:41 AM
  3. Replies: 2
    Last Post: 12-10-2018, 08:22 PM
  4. sorting table field in ascending order
    By picyx in forum Access
    Replies: 7
    Last Post: 11-18-2014, 02:24 PM
  5. How to order columns in ascending order?
    By darkingthereturn in forum Access
    Replies: 5
    Last Post: 06-18-2012, 05: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