+ Reply to Thread
Results 1 to 11 of 11

COUNTIF and COUNTIFS with SUBTOTAL

  1. #1
    Registered User
    Join Date
    09-12-2012
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    14

    COUNTIF and COUNTIFS with SUBTOTAL

    I have googled and used this forum to figure out how to combine SUBTOTAL with other formulas. For instance, here's one formula I've used to calculate an average that ignores cells with a zero value: =AVERAGE((IF(SUBTOTAL(9,OFFSET(L$7,ROW(L$7:L$112)-ROW(L$7),0))<>0,SUBTOTAL(9,OFFSET(L$7,ROW(L$7:L$112)-ROW(L$7),0)))))

    However, I'm not entirely sure what's going on in that formula and I have a more complicated formula that I'd like to reflect the filtered values. Here's the formula: =(COUNTIF(L7:L112, "<0"))/(COUNTIFS(L7:L112,"<>0",P7:P112,"=Yes"))

    It works as intended (gives me a percentage that I'm looking for) but how would I change it to work with SUBTOTAL?

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,957

    Re: COUNTIF and COUNTIFS with SUBTOTAL

    See my next post....
    Last edited by Bernie Deitrick; 08-26-2015 at 01:48 PM.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    09-12-2012
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: COUNTIF and COUNTIFS with SUBTOTAL

    Thanks for your help. However, I tried your formula and it looks like it doesn't work as intended. It still counts all the values in the range and the output value does not change based on what filter is on (and I checked the data, it should definitely change). Unfortunately I don't know enough about array formulas to fix this although they seem to be extremely useful so I need to find time to start learning that.

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,957

    Re: COUNTIF and COUNTIFS with SUBTOTAL

    Sorry, I misunderstood what you were doing. Try a helper column of formulas - let's say, in Q7, use the formula

    =SUBTOTAL(3,L7)

    copied down to Q112

    Then use

    =SUMPRODUCT((L7:L112<0)*Q7:Q112)/SUMPRODUCT((L7:L112<>0)*(P7:P112="Yes")*Q7:Q112)

    If Q is not available, use any open column for the helper formulas and change the two instances of Q7:Q112

  5. #5
    Registered User
    Join Date
    09-12-2012
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: COUNTIF and COUNTIFS with SUBTOTAL

    Thanks very much, that works very well.

    The thing is that my sheet is very "wide" (176 columns in use) and the data is formatted in a way that I'd rather not use helper columns if at all possible. Do you or anyone else know how to achieve the same result without using a helper column - is that even possible?

  6. #6
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,957

    Re: COUNTIF and COUNTIFS with SUBTOTAL

    If you include your filtering criteria in the formula, then you can do away with the SUBTOTAL column of helper cells. But if you want to be able to apply the filters any way you want, and have the filtering changed the range compared to the formula's criteria, then it isn't possible without the helper column unless you use VBA and write a custom UDF.

  7. #7
    Registered User
    Join Date
    09-12-2012
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: COUNTIF and COUNTIFS with SUBTOTAL

    Ok, that makes sense. Thanks very much your help, it's much appreciated!

  8. #8
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: COUNTIF and COUNTIFS with SUBTOTAL

    Quote Originally Posted by JFactor View Post
    =(COUNTIF(L7:L112, "<0"))/(COUNTIFS(L7:L112,"<>0",P7:P112,"=Yes"))

    It works as intended (gives me a percentage that I'm looking for) but how would I change it to work with SUBTOTAL?
    Try this...

    =SUMPRODUCT(SUBTOTAL(2,OFFSET(L7,ROW(L7:L112)-ROW(L7),0)),--(L7:L112<0))/SUMPRODUCT(SUBTOTAL(2,OFFSET(L7,ROW(L7:L112)-ROW(L7),0)),--(L7:L112<>0),--(P7:P112="Yes"))
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  9. #9
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,957

    Re: COUNTIF and COUNTIFS with SUBTOTAL

    I stand corrected, by Tony Valko. Using SUMPRODUCT and a SUBTOTAL with an OFFSET() call allows SUBTOTAL to return the necessary array to not use the column of formulas.

  10. #10
    Registered User
    Join Date
    09-12-2012
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: COUNTIF and COUNTIFS with SUBTOTAL

    Excellent. Thanks Tony Valko, that formula works beautifully.

  11. #11
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: COUNTIF and COUNTIFS with SUBTOTAL

    You're welcome. Thanks for the feedback!

+ 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. SUBTOTAL and COUNTIFS combination
    By aaron_burr in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 06-07-2020, 12:52 AM
  2. [SOLVED] How to Subtotal Countifs with 3 criteria?
    By ExcelFledgling in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 08-03-2015, 03:53 PM
  3. Countifs with subtotal
    By eleaca in forum Excel General
    Replies: 5
    Last Post: 01-04-2015, 12:44 PM
  4. [SOLVED] COUNTIFS and SUBTOTAL Functions Help
    By kapeller in forum Excel General
    Replies: 8
    Last Post: 09-15-2014, 06:23 PM
  5. Subtotal and Countifs
    By pisgah in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-05-2013, 02:14 PM
  6. Subtotal for countifs function
    By guyzk1 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-02-2013, 04:39 PM
  7. [SOLVED] =Subtotal(countif,Range); Subtotal and countif in 1 formula [SOLVED]
    By thomas.mapua in forum Excel General
    Replies: 5
    Last Post: 01-06-2012, 11:33 AM

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