+ Reply to Thread
Results 1 to 11 of 11

COUNTIFs: Multiple ranges, single criterion with OR logic

  1. #1
    Registered User
    Join Date
    04-18-2017
    Location
    Islamabad, Pakistan
    MS-Off Ver
    2013
    Posts
    7

    COUNTIFs: Multiple ranges, single criterion with OR logic

    I have the following sample data:

    Book1.png

    What I want to do:
    -Count the number of events that were organised on EITHER Agenda 1 OR Agenda 2 between March 09, 2017 and June 15, 2017 by each individual.
    Example: Number of events organised by A is 2 (if event has yes in both agenda 1 and agenda 2, it needs to be counted as ONE)

    What I have been able to do:
    I have been using COUNTIFs to do this. Have no trouble whatsoever with using criteria for name, date, type. Following is an example of what my formula looks like:

    =COUNTIFS(Activity_Details!B:B, VLOOKUP(A4,Activity_Details!B:B,1,FALSE), Activity_Details!C:C, "Event", Activity_Details!D:D,">="&DATE(2017,3,9),Activity_Details!D:D,"<="&DATE(2017,6,15), Activity_Details!H:H, "Yes")

    *Where:
    Sheet name: Activity_Details
    Col C = Type
    Col H = Agenda 1
    Col I = Agenda 2
    Col D = Date
    Col B = Name

    What I need help with:
    Within my COUNTIFs, I want to nest a single criterion (="Yes") for two ranges (Agenda 1, Agenda 2) using OR logic, whereby, if both columns have "Yes", it is counted as one.

    Anyone to help would be a savior.
    Attached Images Attached Images
    Last edited by A.Khan; 04-18-2017 at 09:58 AM.

  2. #2
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: COUNTIFs: Multiple ranges, single criterion with OR logic

    Hi,

    Try:

    =SUM(COUNTIFS(Activity_Details!B:B,VLOOKUP(A4,Activity_Details!B:B,1,FALSE),Activity_Details!C:C,"Event",Activity_Details!D:D,">="&DATE(2017,3,9),Activity_Details!D:D,"<="&DATE(2017,6,15),Activity_Details!H:H,{"=","=","<>"}&"Yes",Activity_Details!I:I,{"=","<>","="}&"Yes"))

    although I have to confess that I don't understand the part:

    VLOOKUP(A4,Activity_Details!B:B,1,FALSE)

    which you are using, since this will always return a result which is precisely the same as simply:

    A4

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  3. #3
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2403
    Posts
    43,984

    Re: COUNTIFs: Multiple ranges, single criterion with OR logic

    Will you please attach a SMALL sample Excel workbook (10-20 rows of data is usually enough)? Please don't attach a picture of one (no-one will want to re-type all your stuff before starting).

    1. Make sure that your sample data are truly REPRESENTATIVE of your real data. The use of unrepresentative data is very frustrating and can lead to long delays in reaching a solution.

    2. Make sure that your desired solution is also shown (mock up the results manually).

    3. Make sure that all confidential information is removed first!!

    4. Try to avoid using merged cells. They cause lots of problems!

    Unfortunately the attachment icon doesn't work at the moment. So, to attach an Excel file you have to do the following: Just before posting, scroll down to Go Advanced and then scroll down to Manage Attachments. Now follow the instructions at the top of that screen.
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU.

    Temporary addition of accented to illustrate ongoing problem to the TT: L? fh?ile P?draig sona dhaoibh

  4. #4
    Registered User
    Join Date
    04-18-2017
    Location
    Islamabad, Pakistan
    MS-Off Ver
    2013
    Posts
    7

    Re: COUNTIFs: Multiple ranges, single criterion with OR logic

    Noted. Just joined the forum and still am in the exploratory phase.

  5. #5
    Registered User
    Join Date
    04-18-2017
    Location
    Islamabad, Pakistan
    MS-Off Ver
    2013
    Posts
    7

    Re: COUNTIFs: Multiple ranges, single criterion with OR logic

    Can you explain what this part of the function {"=","=","<>"} does exactly?

    I need to add Agenda 3 to this formula.

  6. #6
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: COUNTIFs: Multiple ranges, single criterion with OR logic

    If in reality the number of columns to consider for the OR criterion is quite large, then it's best to switch to an array formula, since otherwise the required COUNTIFS constructions become both lengthy and impractical.

    For example, assuming this new Agenda 3 is in column J, you would require:

    =SUM(COUNTIFS(Activity_Details!B:B,VLOOKUP(A4,Activity_Details!B:B,1,FALSE),Activity_Details!C:C,"Event",Activity_Details!D:D,">="&DATE(2017,3,9),Activity_Details!D:D,"<="&DATE(2017,6,15),Activity_Details!H:H,{"=","=","=","=","<>","<>","<>"}&"Yes",Activity_Details!I:I,{"=","=","<>","<>","=","=","<>"}&"Yes",Activity_Details!J:J,{"=","<>","=","<>","=","<>","="}&"Yes"))

    The point is to create all permutations from the three columns where at least one of the entries is "Yes". As you can see, however, although the above is perfectly valid, it's neither readily understandable nor easily extendible.

    I would suggest the following array formula**:

    =SUM(IF(Activity_Details!B1:B100=VLOOKUP(A4,Activity_Details!B:B,1,FALSE),IF(Activity_Details!C1:C100="Event",IF(Activity_Details!D1:D100>=DATE(2017,3,9),IF(Activity_Details!D1:D100<=DATE(2017,6,15),IF(MMULT(0+(Activity_Details!H1:J100="Yes"),TRANSPOSE(COLUMN(Activity_Details!H1:J100)^0))>0,1))))))

    again, assuming that the new Agenda 3 column is column J (if not, let me know).

    The only slight downside to this approach is that you would now be strongly advised to not use entire column references (else the above will take an age to calculate). Hence my choice of an upper row reference of 100 here, which obviously you can change (though being sure not to make it too large).

    Regards


    **Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).

  7. #7
    Registered User
    Join Date
    04-18-2017
    Location
    Islamabad, Pakistan
    MS-Off Ver
    2013
    Posts
    7

    Re: COUNTIFs: Multiple ranges, single criterion with OR logic

    This is working perfectly in Excel but not in Google spreadsheets. Do I need to use a different formula for Google spreadsheets?

  8. #8
    Registered User
    Join Date
    04-18-2017
    Location
    Islamabad, Pakistan
    MS-Off Ver
    2013
    Posts
    7

    Re: COUNTIFs: Multiple ranges, single criterion with OR logic

    Quote Originally Posted by XOR LX View Post
    =SUM(IF(Activity_Details!B1:B100=VLOOKUP(A4,Activity_Details!B:B,1,FALSE),IF(Activity_Details!C1:C100="Event",IF(Activity_Details!D1:D100>=DATE(2017,3,9),IF(Activity_Details!D1:D100<=DATE(2017,6,15),IF(MMULT(0+(Activity_Details!H1:J100="Yes"),TRANSPOSE(COLUMN(Activity_Details!H1:J100)^0))>0,1))))))
    [/I]
    ^ This one is working in Google spreadsheets (not the other one though). The only problem is; Agenda 3 is not in an adjacent column. It is in Column E.

  9. #9
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: COUNTIFs: Multiple ranges, single criterion with OR logic

    Then use:

    =SUM(IF(Activity_Details!B1:B100=VLOOKUP(A4,Activity_Details!B:B,1,FALSE),IF(Activity_Details!C1:C100="Event",IF(Activity_Details!D1:D100>=DATE(2017,3,9),IF(Activity_Details!D1:D100<=DATE(2017,6,15),IF((Activity_Details!E1:E100="Yes")+(Activity_Details!H1:H100="Yes")+(Activity_Details!I1:I100="Yes"),1))))))

    Regards

  10. #10
    Registered User
    Join Date
    04-18-2017
    Location
    Islamabad, Pakistan
    MS-Off Ver
    2013
    Posts
    7

    Re: COUNTIFs: Multiple ranges, single criterion with OR logic

    Although this question deviates from the thread, but given the same sample data and your prompt response, I'll take my chance.

    Please see the attached mock spreadsheet that contains all columns.

    I want the same single criterion with OR condition for Agendas in Column E, H and I. The only difference now is that I want to take a conditional sum (same conditions as countif) of the last column of participants (Column Y). I have tried nesting the IF condition you provided in a SUMIF formula but haven't been successful so far.
    Attached Files Attached Files

  11. #11
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: COUNTIFs: Multiple ranges, single criterion with OR logic

    So just replace the 1 at the end of my last formula with the appropriate sum range, i.e.:

    =SUM(IF(Activity_Details!B1:B100=VLOOKUP(A4,Activity_Details!B:B,1,FALSE),IF(Activity_Details!C1:C100="Event",IF(Activity_Details!D1:D100>=DATE(2017,3,9),IF(Activity_Details!D1:D100<=DATE(2017,6,15),IF((Activity_Details!E1:E100="Yes")+(Activity_Details!H1:H100="Yes")+(Activity_Details!I1:I100="Yes"),Activity_Details!Y1:Y100))))))

    Regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 3
    Last Post: 11-22-2016, 06:11 AM
  2. AVERAGEIF - single criterion in multiple columns?
    By oyvindh in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 11-16-2016, 11:10 AM
  3. Replies: 0
    Last Post: 04-16-2015, 02:45 AM
  4. [SOLVED] Looking up multiple values based on a single criterion
    By wmjenner in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-31-2013, 09:38 PM
  5. Text in a single cell based on logic of multiple other cells
    By dtrimble in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-12-2013, 01:33 AM
  6. [SOLVED] Countifs with Multiple Criterion
    By JohnDear in forum Excel General
    Replies: 7
    Last Post: 05-28-2012, 03:56 PM
  7. [SOLVED] Find Multiple instances of Single Criterion in Row & Return To a Single Col
    By Sam via OfficeKB.com in forum Excel Formulas & Functions
    Replies: 16
    Last Post: 05-09-2006, 10:10 PM

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