Results 1 to 7 of 7
  1. #1
    suziebd33 is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Apr 2018
    Posts
    3

    Count Question Across Multiple Fields - Rusty Access User Alert!

    Hi Access Friends!

    It has been quite some time since I used the Access SQL part of my brain, but I am trying to create a simple report with Access 2016 version to do the following:

    COUNT the repeating ticket numbers in fields, "Ticket_1", "Ticket_2", "Ticket_3" and show the total count AS NumberOfCallsPerTicket

    Here is my test table: custom_table

    status addi_status appl call_date call_time tsr subject_id ticket_1 ticket_2 ticket_3
    OS R2 CITE 6/4/2018 8:38:07 PM BSB 1S12345 INC123 INC456 INC789
    OS E2 CBMY 6/4/2018 8:39:20 PM BSB 1S12345 INC123 INC789
    OS E2 CITE 6/4/2018 8:40:31 PM BSB 1S12345 INC123 INC987
    OS R2 CBMY 6/4/2018 8:41:34 PM BSB 1S12345 INC123 INC789
    OS R2 CBMY 6/4/2018 8:42:48 PM BSB 1S12345 INC123 INC456
    IS R1 CITE 6/4/2018 8:46:03 PM BSB 1S98765 INC333


    I have it working when picking out of "ticket_1" column only...
    subject_id ticket_1 NumberOfCallsPerTicket
    1S12345 INC123 5
    1S98765 INC333 1

    Here is my statement for the above:
    SELECT subject_id, ticket_1, COUNT(ticket_1) AS NumberOfTicketsPerCall
    FROM Custom_mycite
    GROUP BY subject_id, ticket_1
    ORDER BY subject_id, ticket_1

    I am trying to get results similar to the below totals which I calculated by hand. I also want to include the "subject_id" field per row/count result as shown in the above screen shot.

    INC123=5
    INC333=1


    INC456=2
    INC789=3
    INC987=1

    Any insight/advice/assistance would be greatly appreciated!!!

    Kind regards,
    suziebd33

  2. #2
    Perceptus's Avatar
    Perceptus is offline Expert
    Windows 10 Access 2016
    Join Date
    Nov 2012
    Location
    Knoxville, Tennessee
    Posts
    659
    This is a bit of a kludge, but would this work for you?

    Code:
    SELECT "Ticket1" as tid, subject_id, ticket_1, COUNT(ticket_1) AS NumberOfTicketsPerCall
    FROM Custom_mycite
    GROUP BY subject_id, ticket_1
    ORDER BY subject_id, ticket_1
    Union All 
    SELECT "Ticket2" as tid, subject_id, ticket_2, COUNT(ticket_2) AS NumberOfTicketsPerCall
    FROM Custom_mycite
    GROUP BY subject_id, ticket_2
    ORDER BY subject_id, ticket_2
    Union All 
    SELECT "Ticket3" as tid, subject_id, ticket_3, COUNT(ticket_3) AS NumberOfTicketsPerCall
    FROM Custom_mycite
    GROUP BY subject_id, ticket_3
    ORDER BY subject_id, ticket_3
    Its also possible that I completely missed what you were looking for. This is the first thing I thought of
    Last edited by Perceptus; 04-09-2018 at 03:33 PM. Reason: Attention Deficit Disorder

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    The repeating fields (ticket 1, etc) are a design mistake:

    Fundamentals of Relational Database Design -- r937.com

    I'd fix the design so those were in a related table. As is, you can use a UNION query to normalize the ticket data and do your counts on that. But it's a workaround, I'd fix the design.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    suziebd33 is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Apr 2018
    Posts
    3
    Quote Originally Posted by pbaldy View Post
    The repeating fields (ticket 1, etc) are a design mistake:

    Fundamentals of Relational Database Design -- r937.com

    I'd fix the design so those were in a related table. As is, you can use a UNION query to normalize the ticket data and do your counts on that. But it's a workaround, I'd fix the design.
    @ Perceptus AND pbaldy: Thanks to you both, I think what I am hearing is create more tables to make this less clunky. I figured I would need to end up doing so, but just wanted to make sure I hadn't forgotten something simple. I haven't used access in ages.

    Back to the drawing board, thanks again to you both!

  5. #5
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    I got notification of a moderated post, but don't see one. Did you delete it? It's moderating because of the link, which will stop after you have a few more posts. It's an anti-spam setting on the forum.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  6. #6
    suziebd33 is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Apr 2018
    Posts
    3
    I didn't delete it, I was trying to thank you both for the quick responses and to let you know that I am taking your advise and going to create a couple more tables to make it less clunky

    Thank you again!
    -Suzebd33

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    It just now showed up (post 4) so I approved it.

    Welcome to the site by the way!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Count where multiple fields are the same
    By Rriemer in forum Access
    Replies: 4
    Last Post: 06-21-2017, 01:31 PM
  2. Rusty access query
    By rkbisme in forum Queries
    Replies: 5
    Last Post: 10-14-2014, 01:44 PM
  3. Replies: 0
    Last Post: 08-20-2013, 09:05 AM
  4. Alert user when inventory below minimum
    By Micky in forum Access
    Replies: 5
    Last Post: 04-06-2012, 03:14 PM
  5. Replies: 2
    Last Post: 01-23-2012, 11:15 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