Results 1 to 5 of 5
  1. #1
    Patrick1977 is offline Novice
    Windows 7 64bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    6

    Thumbs up Counting across a row

    Hello,

    If I have a table that looks like this:

    Row# F1 F2 F3
    1 X X X
    2 X
    3 X X




    How can I count the number of Xs across each row, so that I get

    Row# Count
    1 3
    2 1
    3 2

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    1. bad design of a table

    2. you can get around it in a query ,

    if numeric fld"
    Total: [f1]+[f2]+[f3]

    or not numeric:
    select ROW#, Total: iif(IsNull([f1]),0,1)+ iif(IsNull([f2]),0,1))+ iif(IsNull([f3]),0,1)) from table

  3. #3
    Perceptus's Avatar
    Perceptus is offline Expert
    Windows 7 64bit Access 2007
    Join Date
    Nov 2012
    Location
    Knoxville, Tennessee
    Posts
    659
    Not an access answer. but I would Copy the data to Excel and transpose rows for columns. then you could perform a aggregate count function.

    other wise you could
    Code:
    Public Function countoccurences(ByVal rs As Recordset)
    Dim f As Field, i%: i% = 0
    For Each f In rs.Fields
        If f.Value = "X" Then i% = i% + 1
    Next f
    End Function
    or similar

  4. #4
    Patrick1977 is offline Novice
    Windows 7 64bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    6
    Thank you for your reply.
    I don't deny that is isn't a great table design; I am just trying to get the information that I need from it.

    I hoped to avoid the nested IIF() statements as the real table has > 100 fields.



    Quote Originally Posted by ranman256 View Post
    1. bad design of a table

    2. you can get around it in a query ,

    if numeric fld"
    Total: [f1]+[f2]+[f3]

    or not numeric:
    select ROW#, Total: iif(IsNull([f1]),0,1)+ iif(IsNull([f2]),0,1))+ iif(IsNull([f3]),0,1)) from table

  5. #5
    Patrick1977 is offline Novice
    Windows 7 64bit Access 2013 32bit
    Join Date
    Feb 2016
    Posts
    6
    Thanks for the idea.
    I may try to transpose by modifying the function found here:
    https://www.fmsinc.com/microsoftacce...transpose.html
    and then count rows as normal.



    Quote Originally Posted by Perceptus View Post
    Not an access answer. but I would Copy the data to Excel and transpose rows for columns. then you could perform a aggregate count function.

    other wise you could
    Code:
    Public Function countoccurences(ByVal rs As Recordset)
    Dim f As Field, i%: i% = 0
    For Each f In rs.Fields
        If f.Value = "X" Then i% = i% + 1
    Next f
    End Function
    or similar

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

Similar Threads

  1. Counting Changes
    By Amigo9 in forum Queries
    Replies: 5
    Last Post: 07-28-2015, 06:49 PM
  2. Counting in
    By tngirl in forum Reports
    Replies: 7
    Last Post: 05-24-2013, 11:15 AM
  3. Counting
    By GeirA in forum Queries
    Replies: 7
    Last Post: 02-29-2012, 02:58 PM
  4. Counting Help
    By Jessyx in forum Access
    Replies: 1
    Last Post: 12-03-2011, 01:34 AM
  5. Counting
    By rfs in forum Forms
    Replies: 0
    Last Post: 03-15-2011, 03:20 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