Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Deriving High and Low Non-Zero Values.
Written by Allen Wyatt (last updated July 31, 2021)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365
There may be times when you need to derive the smallest (or largest) value from a range, unless the smallest (or largest) value is zero. For instance, you might have a range of values such as {0, 3, 1, 4, 2}. In this case, the lowest value is zero, but the value you really want returned is 1.
There is no intrinsic function within Excel to return a value as stipulated here. However, you can create a formula that will do the trick. Assuming that the range of values you want to analyze are in C4:C8, the following formula will return the lowest non-zero value:
=IF(MIN(C4:C8)=0,SMALL(C4:C8,COUNTIF(C4:C8,"=0")+1),MIN(C4:C8))
This formula uses the MIN function to determine if the lowest value in the range is zero. If it is, then the SMALL function is used to derive the lowest value, excluding the zeros. (The COUNTIF function returns the number of zeros in the range, and therefore tells SMALL which item from the range to pick.)
A small change to the formula allows it to be used to return the largest non-zero number in a range:
=IF(MAX(C4:C8)=0,LARGE(C4:C8,COUNTIF(C4:C8,"=0")+1),MAX(C4:C8))
These formulas will work for any range, unless the range is made up entirely of zeros. In that instance, a #NUM! error is returned.
If you are using Excel 2019 or Excel in Office 365, you can use the new MINIFS function. It would be used in this manner for this example:
=MINIFS(C4:C8,C4:C8,"<>"&0)
More information on the MINIFS function can be found on this Microsoft Office support page:
https://support.office.com/en-gb/article/minifs-function-6ca1ddaa-079b-4e74-80cc-72eef32e6599
If you prefer to use array formulas, then you can make the formula much shorter. This version returns the lowest non-zero value:
=MIN(IF(C4:C8=0,9^9,C4:C8))
Remember to enter it using Ctrl+Shift+Enter. It also suffers from a problem if all the values in the range are 0; in that case it returns 387420489, which is 9^9. (It would also return that value if all the values in the range were greater than 387420489.)
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9750) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365. You can find a version of this tip for the older menu interface of Excel here: Deriving High and Low Non-Zero Values.
Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!
It is easy to use Excel functions to sum values based on criteria you establish, unless those criteria involve the ...
Discover MoreIf you have a column of data that contains color-coded cells, you may want a way to sum values in the column based on the ...
Discover MoreExcel allows you to easily create names for different ranges in your workbook. If you ever want to clean up the list of ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2021-08-04 09:09:07
Mark Winfield
Hi Allen,
Thanks for your many useful tips - I've followed your site for years and always enjoy reading the tips you write.
A question on this current tip 'Deriving High and Low Non-Zero Values'; I follow the logic of your first formula in the tip but wonder whether you could halve its length by getting rid of the 'IF' and the two 'MIN' functions, and just use:
=SMALL(C4:C8,COUNTIF(C4:C8,"=0")+1)
Have I missed something? Kind regards, Mark
2021-07-31 10:23:39
J. Woolley
You can also use the MINIF and MAXIF functions in My Excel Toolbox:
=MINIF(C4:C8,"<>0")
=MAXIF(C4:C8,"<>0")
MINIF and MAXIF (which are not built-in Excel functions) are designed analogous to SUMIF (which is built-in).
See https://sites.google.com/view/MyExcelToolbox/
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments