Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    larry72450 is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2021
    Posts
    5

    Question Counting How many 'U' per row in query.

    I have a query I created that has 7 days per week x 16 weeks = 112 columns containing absenteeism records for students for a 16 week semester. A single letter. For example: P = Present, U = Unexcused, H = Holiday etc

    How do I count the number of "U" each student has and list the result in a report or a query.

    I exported a sample query in Excel.

    Thanks,

    Larry
    Attached Files Attached Files

  2. #2
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,158
    The short answer is not in that query.
    Is that really a query export?

    Can you show us a sample of the source table and data please.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    larry72450 is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2021
    Posts
    5
    Ive created me a nightmare with this database. I hate the structure of it.

    Here is the table.
    Class_Attendance.zip

  4. #4
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,425
    112 columns containing absenteeism records
    Sounds like a design problem. Counting across columns is never easy in Access. Maybe take a step back and review to see if you followed any of these principles:

    Normalization Parts I, II, III, IV, and V
    http://rogersaccessblog.blogspot.com...on-part-i.html
    and/or
    http://holowczak.com/database-normalization/
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,570
    If you are going to output data like that, do it in Excel ?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Summing across is simple arithmetic.

    field1 + field2 + field3

    However, if field is Null, result of expression will be Null so must handle Null

    Nz(field1,0) + Nz(field2,0) + Nz(field3,0)

    If you want a count based on field content, use IIf

    IIf(field1="U",1,0) + IIf(field2="U",1,0) + IIf(field3="U",1,0)

    Expression can be in query or textbox.
    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.

  7. #7
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,158
    Quote Originally Posted by larry72450 View Post
    Ive created me a nightmare with this database. I hate the structure of it.

    Here is the table.
    Class_Attendance.zip
    I'm afraid I can confirm your diagnosis.
    That isn't a database table, it's a excel spreadsheet dumped into an access table.

    Your attendance records should be in at least 2 tables something like.
    tbL_AttendanceRecords tbl_Students
    AttendanceRecID StudentID_FK AttendDate AttendanceStatus StudentID StudentName DOB OtherStudentSpecificDataGoesHere
    1 1 18/08/2021 U 1 John Doe 01/02/2005
    2 2 18/08/2021 P 2 Jane Doe 02/02/2005
    3 3 18/08/2021 H 3 Frank Doe 03/02/2005
    4 4 18/08/2021 E 4 Susan Doe 04/02/2005
    5 5 18/08/2021 P 5 Alice Doe 05/02/2005
    6 6 18/08/2021 P 6 Henry Doe 06/02/2005
    7 1 19/08/2021 p
    8 2 19/08/2021 p
    9 3 19/08/2021 P
    10 4 19/08/2021 E
    11 5 19/08/2021 H
    12 6 19/08/2021 P
    13 1 20/08/2021 P
    14 2 20/08/2021 P
    15 3 20/08/2021 U
    16 4 20/08/2021 U
    17 5 20/08/2021 U
    18 6 20/08/2021 U



    (I'd have a table for the attendance status as well. Ignore that as a nice to have at the moment)

    But can you now see how easy it is to count up the number of records with a specific attendance type?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  8. #8
    larry72450 is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2021
    Posts
    5
    Yes I can do the iff , but that is a lot of writing, 112 columns for U, 112 to search for A, then P, then H, etc Thats a lot. Access has its limits

    I was hoping for SQL or vb code, dcount that would just hunt all columns for "U" etc

  9. #9
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    I'm not sure of your overall application, but this model may offer some insight. It's the Roster table I'm thinking about; and it could have an associated field that is related to Status that identifies the meanings of your HPUE.

    Instead of multiple iifs, you may consider Select Case --but readers don't know the details of your process(es) nor the audience for any form/reports/statistics.

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Quote Originally Posted by larry72450 View Post
    Yes I can do the iff , but that is a lot of writing, 112 columns for U, 112 to search for A, then P, then H, etc Thats a lot. Access has its limits

    I was hoping for SQL or vb code, dcount that would just hunt all columns for "U" etc
    Yes, that comes with poorly designed db. Normalize!

    Yes, a VBA custom function could be written.
    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.

  11. #11
    larry72450 is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2021
    Posts
    5
    I do plan on re-writing most of this db, if not all this next summer. But for now, everyone is using it and I cannot do a lot. I would like to create a report that does search for all "U" in the SQL query or table in all columns if possible.

    If not I do appreciate all the comments. I did like the examples and help files that was suggested.

  12. #12
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    Please have a look at the attached sample, it should give you what you want but strongly recommend a redesign of your db based on the suggestions received above.

    Cheers,
    Vlad
    Attached Files Attached Files
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  13. #13
    Micron is online now Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,425
    So simple arithmetic doesn't always translate to easy, does it?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  14. #14
    larry72450 is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2021
    Posts
    5
    All I got to say is WOW. I know the hard work you did in doing this and quickly too. and its appreciated a lot. I will be adding this to my current (badly designed) database. Soon i will do a redesign.

  15. #15
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,250
    You're welcome Larry!

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Query and Counting
    By johnberman in forum Queries
    Replies: 4
    Last Post: 11-08-2013, 04:36 AM
  2. Counting TOP/first 10 in Query
    By undee69 in forum Queries
    Replies: 5
    Last Post: 11-20-2012, 09:20 AM
  3. Counting Records in a Query
    By bomich in forum Access
    Replies: 2
    Last Post: 11-16-2012, 03:00 AM
  4. Counting in Query
    By EdwinLawrence in forum Queries
    Replies: 3
    Last Post: 03-05-2012, 12:21 PM
  5. Help with counting Query
    By metalhead22 in forum Queries
    Replies: 8
    Last Post: 04-29-2009, 02:07 AM

Tags for this Thread

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