Results 1 to 2 of 2
  1. #1
    SiebeD is offline Novice
    Windows 10 Access 2016
    Join Date
    Mar 2021
    Posts
    14

    Sort by date AND time

    Hey!

    I have date that shows up every minute. I want to sort out the average for avery hour. I think that i need to do this in a Query but when i do this I use the function 'FORMAT' so then my data wont sort cronological. So i tried usint "DateValue()" but the it sorts the data per day and not per hour anymore. How can I fix this.
    Thanks a lot!

    Here is the SQL code that i am trying out:
    Code:
    SELECT DISTINCTROW (Format([Control1].[P21 Q Time],'ddddd hh:00')) AS [P21 Q Time per dag], Avg(Control1.[P21 Q ValueY]) AS [Gem Van P21 Q ValueY]
    FROM Control1
    GROUP BY (Format([Control1].[P21 Q Time],'ddddd hh:00'));
    then I get this (so the data alphabetical):
    Click image for larger version. 

Name:	zonder.PNG 
Views:	7 
Size:	27.8 KB 
ID:	44584
    And when i try this :
    Code:
    SELECT DISTINCTROW DateValue(Format([Control1].[P21 Q Time],'ddddd hh:00')) AS [P21 Q Time per dag], Avg(Control1.[P21 Q ValueY]) AS [Gem Van P21 Q ValueY]
    FROM Control1
    GROUP BY DateValue(Format([Control1].[P21 Q Time],'ddddd hh:00'));
    It is like this
    Click image for larger version. 

Name:	datevalue.PNG 
Views:	7 
Size:	17.0 KB 
ID:	44585

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    Q1 the base query, get the data in the time range and add the Hour field: HR: format([datefield],"mm/dd/yyy hh:00")
    Q2, uses Q1 to use the hr field to compute AVG.

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

Similar Threads

  1. Replies: 5
    Last Post: 09-16-2018, 04:58 PM
  2. Replies: 6
    Last Post: 04-19-2016, 03:58 PM
  3. Replies: 11
    Last Post: 07-20-2014, 06:22 PM
  4. Replies: 5
    Last Post: 03-19-2014, 02:31 PM
  5. Replies: 1
    Last Post: 03-13-2014, 07:23 PM

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