How to count rows if matching n numbers in Excel

In this article, we will learn to How to count rows if matching at least n numbers in Excel.

Scenario:

In simple words, while working with numbers data. We need to extract the count of rows having atleast, at most or exactly n values from the particular row satisfying the mentioned criteria in Excel. For example if calculating the number of students who are performing under average in tests. We can perform these kind of counting problems in a long list using the Excel formula explained below.

Formula Functions used and formula Syntax:

The following function will be in use. So get to know a little about, before using it.

  1. SUM function
  2. MMULT function
  3. TRANSPOSE function
  4. COLUMN function

We will construct a formula out of these stated functions.

Use the formula:

{ =SUM ( -- ( MMULT ( -- ( (data) < crit ) , TRANSPOSE ( COLUMN (data) ^ 0 ) ) = n ) ) }

Note:  For curly braces ( { } ) Use Ctrl + Shift + Enter when working with arrays or ranges in Excel. This will generate Curly Braces on the formula by default. DO NOT try to hard code curly braces characters.

data : bunch of numbers as data.

= n : exact number of occurrences (use <= for at most or >= for atleast occurances)

crit : criteria to matched with

Example:

All of these might be confusing to understand. So, let's test this formula via running it on the example shown below. Here we have sales data for the particular sales ID in a row. We need to find the count of Sales ID where salesperson have not completed the sales of 40 for exactly 2 times. Here criteria ois <40 and occurrence to be 2 (=2 for exact occurance) 

Formula:

{ =SUM ( -- ( MMULT ( -- ( (C4:H15) < 40 ) , TRANSPOSE ( COLUMN (C4:H15) ^ 0 ) ) = 2 ) )

Explanation:

  • COLUMN function returns array of column number from the first cell in array to the last cell in array. { 3 ; 4 ; 5 ; 7 ; 8}
  • ^0 , this operation with any array numbers returns array of 1s.
  • TRANSPOSE function converts the matrix array's rows to columns and columns to rows. Here the array of 1s in row is converted to array of 6 (1s) in columns. { 1 ; 1 ; 1 ; 1 ; 1 ; 1 } 
  • -- ( (C4:H15) < 40 )  , this operation returns the values as 1s as TRUE values (matched criteria) and 0s as False values.
  • MMULT function takes matrix multiplication of the 2 arrays and returns values as shown below.

= SUM ( -- ( { 1 ; 0 ; 1 ; 0 ; 2 ; 1 ; 0 ; 0 ; 1 ; 2 ; 3 ; 3 } = 2 ) )

  •  SUM function counts the values in array matching 2 as the occurrence is required.
  • Use Ctrl + Shift + Enter in place of  to get the result. As this is an array formula.

Here the arrays to the function are given as array reference. Use double (--) manually Press Enter to get the result.

As you can see in the above image that there are 2 salesperson who have not completed even 40 sales. This is the Count to the corresponding rows in the data where 2 numbers are less than 40. You can customize the count occurrence and criteria to be checked in rows of the table. Now below is the example to get the Count with different criteria and different occurrences.

Count rows matching sales above 100 with 3 as exact occurrence:

Now we would like to get how many of Salesperson are performing moderately good in sales. For this we need to get the count of salesperson who had done sales above 100 with exactly 3 times.

Use the formula:

= SUM ( -- ( MMULT ( -- ( (C4:H15) > 100 ) , TRANSPOSE ( COLUMN (C4:H15) ^ 0 ) ) = 3 ) )

> 100 : number be greater than 100.

= 3 : occurrence be equal to 3

Here the arrays to the function are given as array reference. Use double (--) manually Press Enter to get the result.

As you can see, there are 3 salesperson who are doing moderately fine. This is the Count to the corresponding rows in the data where 3 sale are greater than 100.

Here are all the observational notes regarding using the formula.

Notes:

  1. The formula only works with numbers.
  2. MMULT and TRANSPOSE functions are the matrix function, so inspect before using.
  3. If the formula returns #VALUE error, check for the curly braces must be present in the formula as shown in the examples in the article.
  4. Negation (--) char changes values, TRUEs or 1s to FALSEs or 0s and FALSEs or 0s to TRUEs or 1s .
  5. Operations like equals to ( = ), less than equal to ( <= ), greater than ( > ) or not equals to ( <> ) can be performed within a formula applied, with numbers only.

Hope this article about How to count rows if n matching values in Excel is explanatory. Find more articles on Counting formulas here. If you liked our blogs, share it with your fristarts on Facebook. And also you can follow us on Twitter and Facebook. We would love to hear from you, do let us know how we can improve, complement or innovate our work and make it better for you. Write us at info@exceltip.com

Related Articles :

Find the last row of data with numbers in Excel : In a range of text values find the last of data in excel.

How to use the SUMPRODUCT function in Excel: Returns the SUM after multiplication of values in multiple arrays in excel.

COUNTIFS with Dynamic Criteria Range : Count cells depstartent on other cell values in Excel.

COUNTIFS Two Criteria Match : Count cells matching two different criteria on list in excel.

COUNTIFS With OR For Multiple Criteria : Count cells having multiple criteria match using the OR function.

The COUNTIFS Function in Excel : Count cells dependent on other cell values.

How to Use Countif in VBA in Microsoft Excel : Count cells using Visual Basic for Applications code.

How to use wildcards in excel : Count cells matching phrases using the wildcards in excel

Popular Articles :

50 Excel Shortcut to Increase Your Productivity : Get faster at your task. These 50 shortcuts will make you work even faster on Excel.

How to use the VLOOKUP Function in Excel : This is one of the most used and popular functions of excel that is used to lookup value from different ranges and sheets. 

How to use the COUNTIF function in Excel : Count values with conditions using this amazing function. You don't need to filter your data to count specific values. Countif function is essential to prepare your dashboard.

How to Use SUMIF Function in Excel : This is another dashboard essential function. This helps you sum up values on specific conditions.

Leave a Reply

Your email address will not be published. Required fields are marked *

Terms and Conditions of use

The applications/code on this site are distributed as is and without warranties or liability. In no event shall the owner of the copyrights, or the authors of the applications/code be liable for any loss of profit, any problems or any damage resulting from the use or evaluation of the applications/code.

Visit Us On TwitterVisit Us On FacebookVisit Us On Youtube