How to count checkbox = true per row for multiple columns (10)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nonerd
    New Member
    • Dec 2012
    • 2

    How to count checkbox = true per row for multiple columns (10)

    I'd like to make a column that counts how often a checkbox is true (-1) for a specific row. Specically: I'd like to know how many rows For 2 columns, you can use iif and count function, but that coding becomes to long, since i've got 10 different columns with checkboxes.

    I've tried making an query with the expression: Exp1:-1*([A]+[B]...[I])
    but everytime i run it, it adds 0 columns to my table, which it shouldnt..
    In the query design view I've: -pressed E(total)and
    added the column with rows (IDs) Total: Group BY
    a column with destination (number) with criteria:Exp1:-1*([A]+[B]...{I])and total:expressio n. Then I added the [A]..[I] columns.total: sum. What ar the criteria there?
    Maybe it is because I don' know exactly what to fill in at "update to" and criteria for [A] to [I]?
    Could anyone help?
  • Seth Schrock
    Recognized Expert Specialist
    • Dec 2010
    • 2965

    #2
    It sounds like you have created an UPDATE query instead of a SELECT query. I'm not sure which version of Access you are using, so I can't tell you for sure how to change it to a SELECT query, but in Access 2010, when you enter query design view, you should see the option to change it to a SELECT query in the ribbon bar. This error is why you are getting 0 columns added to your table.

    When you say row, do you mean record or do you have a row of checkboxes on your form that are grouped like that?

    Comment

    • nonerd
      New Member
      • Dec 2012
      • 2

      #3
      Originally posted by Seth Schrock
      It sounds like you have created an UPDATE query instead of a SELECT query. I'm not sure which version of Access you are using, so I can't tell you for sure how to change it to a SELECT query, but in Access 2010, when you enter query design view, you should see the option to change it to a SELECT query in the ribbon bar. This error is why you are getting 0 columns added to your table.

      When you say row, do you mean record or do you have a row of checkboxes on your form that are grouped like that?
      Thanks! I use Access 2010 and you were right; i used update insead of select! About the rows; i have a column stating cases and ever case is coupled to multiple columns with true or false. there still is something wrong with it though, "you tried to excute a query that doesn't include he specified expression ' as part of an aggregate funtion. My lord access is a funny game! this is what i'm trying to do

      Code:
      SELECT tblCases.lCaseId
      FROM tblCases
         INNER JOIN [amount of a-l] 
            ON tblCases.lCaseId = [amount of a-l].ICaseIdI
      GROUP BY tblCases.lCaseId
      HAVING 
         (("Expr2"=
          -1*([a]+[b]+[c]+[d]+[e]+[f]
                  +[g]+[h]+[i]+[j]+[k]+[l]))
            AND ((Sum(tblCases.a))=True) 
             AND ((Sum(tblCases.b))=True)
              AND ((Sum(tblCases.c))=True)
               AND ((Sum(tblCases.d))=True)
                AND ((Sum(tblCases.e))=True)
                 AND ((Sum(tblCases.f))=True)
                  AND ((Sum(tblCases.g))=True) 
                   AND ((Sum(tblCases.h))=True)
                    AND ((Sum(tblCases.i))=True) 
                     AND ((Sum(tblCases.j))=True) 
                      AND ((Sum(tblCases.k))=True) 
                       AND ((Sum(tblCases.l))=True));
      Last edited by zmbd; Dec 5 '12, 07:02 AM. Reason: [Z:{Stepped the SQL...}]

      Comment

      • zmbd
        Recognized Expert Moderator Expert
        • Mar 2012
        • 5501

        #4
        Start here: Aggregate Query Woes

        Sorry it's very late here so I'll take a look at this once I've had a nap; however, at first blush, you're doing this the almost the very hardest way possible.

        It would help to have an idea of the data and the tables:
        Table Name: tbl_one
        [PK] autonumber
        [Field1] Long
        [Field2] Boolean
        [Field3] long foreign key to tbl_two 1:M

        (1)(990)(True)( 10)
        (2)(991)(True)( 20)
        (3)(992)(True)( 30)

        And the like for the second table

        Then a short example of what you'd like the output to look like.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32661

          #5
          It seems to me like you've managed to get yourself into a real muddle here. That's not something to worry about, but I think maybe you've gone past what you need due to other confusions.

          If you have a bunch of columns (or fields as we say in Access) that are all boolean (They can store either True or False.) and you want a new column in your query that reflects how many of those fields have True values across the whole row (or Record in Access) then your earlier attempt was almost there. Assuming for now that these fields are named [A] to [J] then you want :
          Code:
          NumTrues: -([A]+[B]+[C]+[D]+[E]+[F]+[G]+[H]+[I]+[J])
          As True is numerically equivalent to -1 (just as False is 0) the sum of the fields would be negative, so it needs to be negated.

          NB. Please also respond to Z's post, even if this turns out to be a complete answer for you.

          Comment

          Working...