+ Reply to Thread
Results 1 to 8 of 8

Filter countif problem

  1. #1
    Registered User
    Join Date
    06-17-2018
    Location
    Europe
    MS-Off Ver
    office 365
    Posts
    9

    Question Filter countif problem

    Hello,

    I am hoping and guessing this is a pretty straight forward problem.
    I am wanting to use a countif (or suitable alternative) to count the number of occurrences above a certain value in column B whilst then applying a filter to column A.
    Simple to do using countif when not filter is applied to column A, but obviously not the correct formula to use when I do need to employ the filter in column A.

    I hope this makes sense.

  2. #2
    Forum Contributor
    Join Date
    06-07-2018
    Location
    Newcastle Upon Tyne, England
    MS-Off Ver
    365
    Posts
    143

    Re: Filter countif problem

    Can you upload the document to make it easier?

  3. #3
    Registered User
    Join Date
    06-17-2018
    Location
    Europe
    MS-Off Ver
    office 365
    Posts
    9

    Re: Filter countif problem

    I have attached an example of the problem.
    Attached Files Attached Files

  4. #4
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Filter countif problem

    Hi grdnryn. Welcome to the forum.

    With target % in E1 try
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Then filter and see what happens.
    Dave

  5. #5
    Registered User
    Join Date
    06-17-2018
    Location
    Europe
    MS-Off Ver
    office 365
    Posts
    9

    Re: Filter countif problem

    Yep, that solved it. Much appreciated Dave.

    I don't completely grasp how this formula solves what I am looking for.
    If you have a spare moment would you be able to break down what it is doing so that I can conceptualize in my head what it is going on.
    No dramas if you don't, and thanks again.

  6. #6
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Filter countif problem

    I'll do my best.

    This explanation makes heavy use of the F9 function key (upper keyboard) and the Evaluate Formula feature found on the ribbon (Formulas > Evaluate formula). You can follow along using F9 in the steps below.

    I have made a much smaller version of your upload for this. The reasons will become apparent.

    In D1 of the attached find this formula. It's the same one as before only referencing a much smaller range.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    With D1 the active cell select this portion of the formula in the formula bar and hit F9.

    OFFSET(B3,ROW(B3:B102)-MIN(ROW(B3:B102)),,)

    You will see an "array" of each number that is in B3:B102. What is important to understand here is that OFFSET has the ability to return ranges as separate discreet cells even though the returns appear to be an array in memory. That's important because this set of discreet cells is being passed to SUBTOTAL, and SUBTOTAL will only accept ranges and discreet cell references ... never arrays.

    Extend the selection in the formula bar to include the following and hit F9 again.

    SUBTOTAL(2,OFFSET(B3,ROW(B3:B102)-MIN(ROW(B3:B102)),,))

    You will see an array of all ones. This is because SUBTOTAL (function_num 2) returns a count of each number in each of those OFFSET returns.

    This is not so exciting so far. What is important to know in this step is that SUBTOTAL has the ability to ignore invisible and hidden rows. For count the function numbers are 2 and 102. Check the help file on those.

    In this case it's a no-brainer. The counts are all 1s which is what we want for the next steps.

    Now select just this portion of the formula and hit F9.

    (B3:B102>E1)

    You will see an array of TRUE/FALSE. When math operations are performed on these it coerces TRUE/FALSE into their underlying numeric values 1/0.

    Extend the selection to include this (and hit F9).

    ((B3:B102>E1)*SUBTOTAL(2,OFFSET(B3,ROW(B3:B102)-MIN(ROW(B3:B102)),,)))

    You will see an array of resulting 1s and 0s. SUMPRODUCT then sums those up.

    The filtering "magic" is in the SUBTOTAL function.

    Now using F9 examines each step out of context. You have to intuit the order in which to do it.

    Try applying Evaluate Formula (aka: Fx) to see all of this in context.

    With D1 active and the Evaluate formula dialogue window visible click "Evaluate" repeatedly. Each click reveals step-by-step how Excel solves the formula. Each step is in context.

    You will recall I said that the reasons for a smaller file would become apparent. Well here it is. The viewing port is painfully small. Try using it on the original upload.

    Now repeat all the F9 steps above with the data filtered. Can you tell me what is happening differently?

    Does this help?
    Attached Files Attached Files
    Last edited by FlameRetired; 06-26-2018 at 10:01 PM.

  7. #7
    Registered User
    Join Date
    06-17-2018
    Location
    Europe
    MS-Off Ver
    office 365
    Posts
    9

    Re: Filter countif problem

    That is extremely helpful and very much appreciated. I would never have come to this understanding without this description. Thank you.

  8. #8
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2403
    Posts
    13,406

    Re: Filter countif problem

    You are welcome. Glad it helps. Thank you for the feedback.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ 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. [Solved] Problem with filter (filter with data in a row)
    By Dyordedgar in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-29-2017, 04:30 PM
  2. Using Countif with filter formula
    By Mike Santuile in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 08-31-2016, 05:48 AM
  3. Countif with filter
    By Gaellus in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-25-2016, 07:19 AM
  4. countif function + filter
    By Copiloc in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-11-2016, 12:38 AM
  5. Filter & COUNTIF
    By longbow007 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-13-2009, 07:37 PM
  6. Auto Filter with COUNTIF
    By taichi56 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-21-2008, 03:15 PM
  7. How do I run a filter then have my countif change?
    By dtg_denver in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 12:05 PM

Tags for this Thread

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