Results 1 to 15 of 15
  1. #1
    TrulyVisceral is offline Total N00B
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2018
    Location
    Deimos
    Posts
    102

    Lightbulb A query that tells me how many Incidents between certain hours.


    Click image for larger version. 

Name:	2.png 
Views:	14 
Size:	27.1 KB 
ID:	33887
    This is an Excel chart, but I just wanted to give a visual example.
    What I really wanted to do can't be done due to limitations in the Access chart creation apparently. As such, I got told to do something else with the chart instead.
    I wanted to create a query that tells me how many incidents there were between the hours of each of those three sections (6-8, 8-17 and 17-21).

    I dunno what you'd need to help me in this. Please tell :3

  2. #2
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Ok I'll answer this as well.
    One way would be to create a table with two fields - IncidentHour (0-23) and GroupName
    Now join this table and your incident table or query joining by IncidentHour.
    Convert to aggregate query by clicking the Totals button, group by IncidentHour and Sum the Incidents field
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  3. #3
    TrulyVisceral is offline Total N00B
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2018
    Location
    Deimos
    Posts
    102
    Quote Originally Posted by ridders52 View Post
    Ok I'll answer this as well.
    One way would be to create a table with two fields - IncidentHour (0-23) and GroupName
    Wait, do I put the numbers 0 through 23 in the IncidentHour field, while leaving the GroupName empty?

    Coolcool.

  4. #4
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    No - you need to populate the GroupName field as well e.g. A, B, C or possibly use the labels similar to those shown in your chart.
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  5. #5
    TrulyVisceral is offline Total N00B
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2018
    Location
    Deimos
    Posts
    102

    Unhappy

    Quote Originally Posted by ridders52 View Post
    No - you need to populate the GroupName field as well e.g. A, B, C or possibly use the labels similar to those shown in your chart.
    Ai'ght, I'm back. Maybe I should provide the following:

    1)The graph (without the coloured sections) comes from this query
    Click image for larger version. 

Name:	3.png 
Views:	12 
Size:	35.9 KB 
ID:	33891
    2)"DigHoras" is just the numbers 0-23

    3)"QRYPastHoras" is the same as point #1, but it doesn't show those that don't have entries:
    Click image for larger version. 

Name:	4.png 
Views:	12 
Size:	32.6 KB 
ID:	33892


    edit: I feel like I'm misunderstanding something (as usual).
    The end result is simply to have 3 groups, displaying the sums of all incidents between the hours of 6-8, 8-17 and 17-21
    This is gonna give that? Cause I feel I gave some info wrong, if my understanding of your solution is correct.

  6. #6
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,421
    see if this gets you started
    Code:
    SELECT DISTINCT DSum("[Cantidad]","[PastHoras]","[Hora]>=6 and [Hora]<=8") AS Expr1, 
    DSum("[Cantidad]","[PastHoras]","[Hora]>=8 and [Hora]<=17") AS Expr2
    FROM PastHoras;
    This assumes the table/query is named PastHoras with fields Cantidad and Hora.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  7. #7
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    QRYPastHoras" is the same as point #1, but it doesn't show those that don't have entries:
    I've already answered this point for someone recently - possibly you?
    If not, I'll get back to you if necessary. Logging off for a while
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  8. #8
    TrulyVisceral is offline Total N00B
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2018
    Location
    Deimos
    Posts
    102

    Exclamation

    Quote Originally Posted by ridders52 View Post
    I've already answered this point for someone recently - possibly you?
    If not, I'll get back to you if necessary. Logging off for a while
    It was, yes, the answer is #1. Sorry for going off for a day, I had other stuff to do. Anyways, I could do nothing with the answer you gave me, made the table but... what then?
    Click image for larger version. 

Name:	1.png 
Views:	9 
Size:	10.3 KB 
ID:	33901
    This is basically what I understood, group by hour and then sum the totals. But the resulting table is exactly the same as the original query.

    Quote Originally Posted by Micron View Post
    see if this gets you started
    Code:
    SELECT DISTINCT DSum("[Cantidad]","[PastHoras]","[Hora]>=6 and [Hora]<=8") AS Expr1, 
    DSum("[Cantidad]","[PastHoras]","[Hora]>=8 and [Hora]<=17") AS Expr2
    FROM PastHoras;
    This assumes the table/query is named PastHoras with fields Cantidad and Hora.
    Well, the query is QRYPastHoras, so close enough. So I did that and got this:

    Expr1 Expr2
    62 430

    I'm assuming it just summed everything together.

  9. #9
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,421
    Yes. You change Expr to something more meaningful. E.g. "SixToEight". Probably not a valid solution if the time slots you need will fluctuate.

  10. #10
    TrulyVisceral is offline Total N00B
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2018
    Location
    Deimos
    Posts
    102
    Ok, cool... HOWEVER, those are ALL of the incidents summed together, not just of 6-8?
    But what about the other 2 slots? 8-17 and 17-21.

    Hold on, I got something.

  11. #11
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    Back in post #1, you wrote this:
    I wanted to create a query that tells me how many incidents there were between the hours of each of those three sections (6-8, 8-17 and 17-21).
    My suggestions were designed to achieve that
    See attached for an example database showing what I mean

    I get confused by your mixture of languages which I'll refer to as Spanglish so I've largely ignored your naming apart from Hora

    I've coped the first set of data from post #5 - I realise this is a query but as I don't have the underlying data, I've used a table for this: tblIncidentTotals
    I've added a second table as suggested earlier: tblHourGroups with 2 fields: Hora & GroupName
    I've populated this as 5 groups A-E to include all the hours on your chart
    A: 0-6; B: 6/7; C: 8-16; D: 18-21; E 22/23 which means B/C/D are your coloured graph sections

    Finally I've made a query qryGroupIncidentTotals with these results

    Click image for larger version. 

Name:	Capture.PNG 
Views:	10 
Size:	7.6 KB 
ID:	33903

    See attached database. Hopefully you can adapt to suit your needs
    Attached Files Attached Files
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  12. #12
    TrulyVisceral is offline Total N00B
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2018
    Location
    Deimos
    Posts
    102
    Quote Originally Posted by ridders52 View Post
    I get confused by your mixture of languages which I'll refer to as Spanglish so I've largely ignored your naming apart from Hora
    That is exactly that (it's an actual term, btw. Spanglish I mean). Bad habit, haven't stopped for years, it gets confusing for me and everyone, because I always work in english, but not everyone around me does, so it's weird m8. Hell, not even my supervisor has that much of a grasp on english. Also, I try to make some names shorter, so as to not give that much of a headache when it comes to programming, and because ssome spanish words are longer than english (eg. Past < Pasado) even if it's just a few letters, I tend to do that.

    Anyways, thanks for this m8. I just changed the ABC Naming to the actual groups (6-8 etc...).
    Click image for larger version. 

Name:	2.png 
Views:	9 
Size:	6.5 KB 
ID:	33905

    I'll try to make all future projects entirely in english, just to make it easier whenever I ask for help.

  13. #13
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    One suggestion. Add another field to your tblHourGroups which is either A-E as I did or more simply 1-5.
    Then add that as the first field of your final query shown above so it sorts them in the correct order.
    The field doesn't need to be visible
    At the moment the groups are sorted in 'alphabetical order' as the fields are text

    BTW I've no idea what your comment Y33T means in the rep points section - Spanglish again or intended as an emoji?
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

  14. #14
    TrulyVisceral is offline Total N00B
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2018
    Location
    Deimos
    Posts
    102
    Quote Originally Posted by ridders52 View Post
    One suggestion. Add another field to your tblHourGroups which is either A-E as I did or more simply 1-5.
    Then add that as the first field of your final query shown above so it sorts them in the correct order.
    The field doesn't need to be visible
    At the moment the groups are sorted in 'alphabetical order' as the fields are text

    BTW I've no idea what your comment Y33T means in the rep points section - Spanglish again or intended as an emoji?
    Quote Originally Posted by From Urban Dictionary and Bustle.com
    Term used to express excitement; especially used in basketball when someone has shot a three-pointer that they are sure will go in the hoop.
    Also, it's in "leet speak" (stylized: 1337 5P34K). it's just "Yeet".

    Click image for larger version. 

Name:	4.png 
Views:	8 
Size:	30.8 KB 
ID:	33906

  15. #15
    isladogs's Avatar
    isladogs is offline Access MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    6,204
    LOL. I expect everyone except me knew that without needing it explained...
    Colin Riddington, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I know I don't know, I keep quiet!

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

Similar Threads

  1. Replies: 3
    Last Post: 04-11-2018, 07:38 AM
  2. Replies: 5
    Last Post: 08-30-2015, 05:17 AM
  3. Replies: 1
    Last Post: 01-20-2015, 12:27 PM
  4. Replies: 1
    Last Post: 08-08-2012, 01:42 PM
  5. Replies: 4
    Last Post: 08-06-2012, 10:25 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