+ Reply to Thread
Results 1 to 7 of 7

Count Number of Instances Column B >= Column A Without Helper Cells

Hybrid View

TheMechEngineer Count Number of Instances... 02-17-2022, 09:09 PM
Pete_UK Re: Count Number of Instances... 02-17-2022, 09:28 PM
dflak Re: Count Number of Instances... 02-17-2022, 09:35 PM
TheMechEngineer Re: Count Number of Instances... 02-17-2022, 09:37 PM
dflak Re: Count Number of Instances... 02-17-2022, 09:44 PM
TheMechEngineer Re: Count Number of Instances... 02-17-2022, 09:53 PM
Pete_UK Re: Count Number of Instances... 02-17-2022, 10:05 PM
  1. #1
    Forum Contributor
    Join Date
    06-14-2016
    Location
    Brookland, Arkansas
    MS-Off Ver
    2007,2021
    Posts
    132

    Count Number of Instances Column B >= Column A Without Helper Cells

    As the description says I have two columns full of numbers. I want to count all the instances that the value in column B is >= its counterpart in column A. I have done this with helper cells but want to create an array based formula that does not require a helper column. I have attached an excel sheet that shows the output I should get using the helper column, and a formula I tried using to cut that column out. I left the equal sign out of G7 on purpose, because it just errors out as a function, and I wanted to show the path I tried to take to solve the problem.
    Attached Files Attached Files
    Who needs a life when you have Excel.

  2. #2
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,408

    Re: Count Number of Instances Column B >= Column A Without Helper Cells

    You can use this formula:

    =SUMPRODUCT(--(C3:C5<D3:D5))

    No need for helpers.

    Hope this helps.

    Pete

  3. #3
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,956

    Re: Count Number of Instances Column B >= Column A Without Helper Cells

    First of all I converted the range into a table because tables are dynamic: they know how big they are and also you can define formulas in terms of column headings which make them easier to understand. In general Excel life goes a lot better if your data are in tables.

    Then I use an obscure formula called SUMPRODUCT. SUMPRODUCT is semi retired since SUMIFS, COUNTIFS, AVERAGEIFS, etc. came along. However, there are still some applications, such as this one where it is still useful. SUMPRODUCT means sum of the products and it has a syntax of

    =SUMPRODUCT ((Condition 1) * (Condition 2) * ... (Condition N) * C) Each of the conditions can be complex formulas that evaluate to TRUE or FALSE. TRUE is 1 and False is Zero. The C is an optional constant. Without the C it acts sort of like COUNTIFS. With the C it acts like SUMIFS where the C is the column you want to sum up. Also you can think of * as an AND condition and + as an OR condition and you can nest these within parenthesis. Suffice it to say, you can build some very complex evaluations with SUMPRODUCT.

    In this case the magic formula In cell G3 is =SUMPRODUCT((Table1[B]>Table1[A]) *1) It means count up all the rows where B > A and multiply the count by 1.

    You can play with this by adding rows to the table simply make an entry below the last row in the table and it becomes part of the table. Since the formula is built using the table, it will adjust to use exactly the right amount of rows.
    Attached Files Attached Files
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

  4. #4
    Forum Contributor
    Join Date
    06-14-2016
    Location
    Brookland, Arkansas
    MS-Off Ver
    2007,2021
    Posts
    132

    Re: Count Number of Instances Column B >= Column A Without Helper Cells

    That's a very interesting solution Pete, and yes it does exactly what I wanted. If you don't mind how does that work exactly? I cant figure out how putting 2 "-" converts that to a count function or gets to work without needing an array formatting.

  5. #5
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,956

    Re: Count Number of Instances Column B >= Column A Without Helper Cells

    Pete beat me to it. The -- means "evaluate this expression." It is the method most articles use.

    I prefer to use * and + because it makes more sense to me. 1 * 1 is 1 and anything * 0 is 0.

    Something like SUMPRODUCT ((A=1)*(B=2) * ((C=3) + (D=4))) is true if A AND B are true AND either (C OR D) are true.

    I think the * + method gives more flexibility and for me, at least, is more intuitive.

  6. #6
    Forum Contributor
    Join Date
    06-14-2016
    Location
    Brookland, Arkansas
    MS-Off Ver
    2007,2021
    Posts
    132

    Re: Count Number of Instances Column B >= Column A Without Helper Cells

    Thank You dflak.

    I like your use of mathematics to create Boolean logic. It makes it perfect sense in your example as you laid it out. This was a good learning experience to add tools to my belt.

  7. #7
    Forum Guru Pete_UK's Avatar
    Join Date
    12-31-2011
    Location
    Warrington, England
    MS-Off Ver
    Office 2019 (still learning)
    Posts
    25,408

    Re: Count Number of Instances Column B >= Column A Without Helper Cells

    A Boolean expression returns the values TRUE or FALSE. As the expression in the formula above involves ranges of values, the expression produces an array of logical values (the SUMPRODUCT function takes each element of the range in turn). The use of the double minus coerces these logical values into the numeric values 1 and 0, which can then be summed to give a count.

    Thanks for the rep - glad I could help.

    If that takes care of your original question, please take a moment to select Thread Tools from the menu above and to the right of your first post in this thread, and mark the thread as SOLVED.

    Pete

+ 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] Formula to count number of Vlookup result without helper column
    By jp16 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 10-19-2018, 04:26 AM
  2. [SOLVED] Count the number of instances of a Date in a Column in Another Workbook
    By bigtunelover in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 04-08-2016, 12:23 PM
  3. [SOLVED] Count number of instances of a character in a column of cells
    By mforbes6186 in forum Excel General
    Replies: 3
    Last Post: 02-09-2013, 12:12 PM
  4. [SOLVED] TC Counter -- identify and count number of instances in a selected column.
    By mrodrigues in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 10-29-2012, 03:13 PM
  5. Count number of instances of a value in a column
    By Nate Westcott in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-09-2012, 05:35 PM
  6. Replies: 5
    Last Post: 09-01-2011, 03:46 AM
  7. Count instances of a number in a column
    By k2extrem5 in forum Excel General
    Replies: 2
    Last Post: 01-19-2005, 06:30 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