Counting Values within 10% of a Target

Written by Allen Wyatt (last updated October 5, 2024)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021


Mike has a column in his worksheet that contains numeric values. Some are static values, while others are the result of formulas. He needs a count of all values in the column that are within 10% of a target value. So, if the target value is 5, then Mike needs a count of all values in the column that are between 4.5 and 5.5.

This can be done with the COUNTIFS function, which counts the number of values that match multiple criteria. In generating a count, it doesn't really matter if the values in the column are static or generated by a formula. Here, for instance, is a formula that will produce the count that Mike needs:

=COUNTIFS(A:A,">=4.5",A:A,"<=5.5")

The COUNTIFS function requires "pairs" of parameters, with the first one being the range to be evaluated and the second being the comparison that needs to be used against the range. So, in this instance, all the values in column A are compared to see if they are greater than or equal to 4.5 and the same range is compared to see if the values are less than or equal to 5.5.

You can make the formula more flexible by using the desired target value and calculating the 10% below and above, in this manner:

=COUNTIFS(A:A,">="&5*0.9,A:A,"<="&5*1.1)

In this case, notice that the comparison can be considered TRUE (and thus included in the count) if the value is inclusively between 4.5 and 5.5. If you prefer that the match not be inclusive, then you simply have to change the comparison operator:

=COUNTIFS(A:A,">"&5*0.9,A:A,"<"&5*1.1)

You could, of course, replace the in-formula target value with a cell reference that would, in turn, contain the target value:

=COUNTIFS(A:A,">"&B1*0.9,A:A,"<"&B1*1.1)

There are other approaches you can use besides the COUNTIFS function, if you prefer. For instance, either of the following will work just fine, once the target value is in cell B1:

=SUMPRODUCT((A:A>=B1*0.9)*(A:A<=B1*1.1))
=SUM(--(ABS(A:A/B1-1)<=0.1))

If you are using an older version of Excel (older than Excel 2021 or the Excel in Microsoft 365), then you'll need to enter these as array formulas using Ctrl+Shift+Enter.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (6070) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Determining If the End of a Text File Has Been Reached

When writing a macro that processes a text file, you may need to know when the end of the file has been reached. This is ...

Discover More

Nifty Zooming

If you are using a mouse that has a center wheel, you can use the wheel to zoom in and out of your work. This tip shows ...

Discover More

Setting Orientation of Cell Values

Need the contents of a cell to be shown in a direction different than normal? Excel makes it easy to have your content ...

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

More ExcelTips (ribbon)

Keeping a Max Value in a Cell

Sometimes it is helpful to have a cell contain the maximum value that has ever occurred within changing data. This tip ...

Discover More

Transposing and Linking

Sometimes it is helpful to look at data that is rotated 90 degrees. Excel allows you to use Paste Special to transpose ...

Discover More

Extracting a State and a ZIP Code

Excel is often used to process or edit data in some way. For example, you may have a bunch of addresses from which you ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 2 + 2?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.