+ Reply to Thread
Results 1 to 7 of 7

multiple logical tests as argument in Database function

  1. #1
    Forum Contributor
    Join Date
    09-23-2008
    Location
    Rhode Island
    MS-Off Ver
    Excel for Mac 2011 and 2007 on PC
    Posts
    265

    multiple logical tests as argument in Database function

    I'm trying to use the =AND function as a case selection argument within the range selected as the criteria for a database function.

    So in simpler cases I am used to putting say <26 in the age column if I want the DCOUNT function to count all the cases of those under 26.

    But suppose I wanted to get it to count those under 26 and those over 66.

    I tried putting in: =AND(<26,>66) and I get a rejection for an incomplete formula.

    I also tried entering the address for the first data filled cell of that field (e.g. =AND(K2<26,K2>66) in the database and got an answer for that single cell but not a apparent sorting function to apply that case selection across the entire database field.

    Obviously I could interrogate with two DCOUNT functions and then add the results together, but I'm assuming this can be done in one step.Can anyone get me going in the right direction.

    (Currently using Excel 2004 I think on a Mac)

    thanks,

    brian

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: multiple logical tests as argument in Database function

    Wouldn't you just add the criteria twice, once with a <26 test and the other with >66 test, ie

    =DCOUNT(A1:A10,1,C1:D2)

    Where C1:D1 = A1 presumably and C2:D2 hold < 26, >66 respectively

    Post a file so we can see what you're working with in terms of ranges etc...

  3. #3
    Forum Contributor
    Join Date
    09-23-2008
    Location
    Rhode Island
    MS-Off Ver
    Excel for Mac 2011 and 2007 on PC
    Posts
    265

    Re: multiple logical tests as argument in Database function

    Quote Originally Posted by DonkeyOte View Post
    Wouldn't you just add the criteria twice, once with a <26 test and the other with >66 test, ie

    =DCOUNT(A1:A10,1,C1:D2)

    Where C1:D1 = A1 presumably and C2:D2 hold < 26, >66 respectively

    Post a file so we can see what you're working with in terms of ranges etc...
    Sorry, don't know how to post a file or snippet. I tried the manage attachments link and get a message that I'm not signed in or don't have permission, but I am signed in so maybe I don't post frequently enough or it may be some weird cookie thing. This happens to me all the time with the particular forum engine used here and elsewhere. I''ve signed in, gone through the welcome screen and been redirected to the page I was working on. Up in the right hand corner it says welcome, riwiseuse. But I go to post and get a reply that says I can't do that because I'm not signed in. So I sign in again and sometimes it just goes ahead and makes my post and sometimes it's just lost somewhere and I have to start over, so I've gotten pretty careful to copy my posts to the clipboard before clicking "post" . Sorry for that. You're the functions forum, not the IT manager, and this is not peculiar to excelforum. Every forum I use that the same thread engine you do gives me the same trouble.

    Anyway,

    my formula looks like this:

    =DCOUNT(A1:AA4191,2,A4267:AA4268)

    In the target criteria range I place 1/2 of a conditional statement, e.g., <100, in the criteria column that corresponds to the column (or field) I want to use for case selection. As you can see with the coordinate column designations from the database and criteria, I line up my criteria under the database so the field letters correspond, but I don't think that is necessary so long as the criteria has the same number of fields as the database.

    Assuming that the various case selection criteria are met in a particular record, then this function adds 1 to the count for each record that has a non-text ,non-blank value in field 2.

    As you can see from the range there are 27 fields in the database, and I can place a single conditional test in any or all of these fields so I am able to run multiple tests at once. However, my problem is multiple conditionals against a single field.

    So I have no problem if I have a column for age and one for weight, counting people who are over 30 and under 150 lbs. because those tests are entered in different criteria fields. But If I want to find those over 30 but not 55, where both tests have to be applied to the age field, I cannot figure out how to do it.

    I tried making up a quick test database to use your example and it does not work. I assume this is because it is a single field database but you have specified a two field criterion, i.e. the database has one field in column A, but the criterion specified has two fields in columns C and D. It seems that you weere thinking when you specified field 1 as the second argument in your sample function that the criteria would be used to test field 1, but field 1 is only tested for a non-text, non-blank value, the ordinary function of =COUNT. The limitations or "case selection" are effected by the relation of the conditionals in the criteria range to the relevant fields in the database, not to the field specified for the purposes of counting.

    Hope this explanation is helpful.

    Thanks,

    Brian
    Last edited by riwiseuse; 08-07-2009 at 07:12 AM. Reason: syntax

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,056

    Re: multiple logical tests as argument in Database function

    You need to have <26 on one line and >66 on another in your criteria range to get an OR criterion.
    Everyone who confuses correlation and causation ends up dead.

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: multiple logical tests as argument in Database function

    I tried making up a quick test database to use your example and it does not work. I assume this is because it is a single field database but you have specified a two field criterion, i.e. the database has one field in column A, but the criterion specified has two fields in columns C and D. It seems that you weere thinking when you specified field 1 as the second argument in your sample function that the criteria would be used to test field 1, but field 1 is only tested for a non-text, non-blank value, the ordinary function of =COUNT. The limitations or "case selection" are effected by the relation of the conditionals in the criteria range to the relevant fields in the database, not to the field specified for the purposes of counting.
    See attached - the key is the point that header in C1:D1 = A1 ... ie 2 criterion for the same field.
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    09-23-2008
    Location
    Rhode Island
    MS-Off Ver
    Excel for Mac 2011 and 2007 on PC
    Posts
    265

    Re: multiple logical tests as argument in Database function

    Quote Originally Posted by DonkeyOte View Post
    See attached - the key is the point that header in C1:D1 = A1 ... ie 2 criterion for the same field.
    Got it. I actually did that correctly in my test, but when I specified the database, I wasn't paying close attention and my range included only the values and left the header out, so it didn't match to either criteria, and i assumed it was confused because the number of fields in the criteria was greater than the database.

    I looked in the other opitons for posts to see how you mark a thread as "SOLVED", but I couldn't find it. Maybe that is just the discretion of the moderator, or is that something I can do?

    Thanks,

    Brian

    PS - I still think, a single cell function of some sort that takes multiple arguments similar to an AND function would allow you to leave a large multi field database more logically related to its criteria but using two fields both titled the same as the field you are applying them to works fine.
    Last edited by riwiseuse; 08-09-2009 at 07:28 AM. Reason: clarity

  7. #7
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: multiple logical tests as argument in Database function

    Quote Originally Posted by riwiseuse View Post
    I looked in the other opitons for posts to see how you mark a thread as "SOLVED", but I couldn't find it. Maybe that is just the discretion of the moderator, or is that something I can do?
    See the first box under the Search options in the FAQ section:

    http://www.excelforum.com/faq.php

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1