+ Reply to Thread
Results 1 to 23 of 23

SMALL function to exclude zero values?

  1. #1
    Registered User
    Join Date
    01-28-2020
    Location
    Montgomery, Alabama
    MS-Off Ver
    Office 365
    Posts
    9

    Question SMALL function to exclude zero values?

    I am using the SMALL formula to rank the lowest x number of values in a data set connected to a pivot table. However, I want to EXCLUDE zero values. To clarify, negative numbers and positive numbers are both OK to display, just not zeros. Is this possible?

    Thanks in advance.
    Last edited by TME; 01-28-2020 at 01:52 PM.

  2. #2
    Forum Expert BMV's Avatar
    Join Date
    01-13-2020
    Location
    St-Petersburg, Russia
    MS-Off Ver
    2013-2016
    Posts
    1,329

    Re: SMALL function to exclude zero values?

    use array formula
    Please Login or Register  to view this content.
    .. or
    Please Login or Register  to view this content.
    if negative values must be calculated then <>0.
    Last edited by BMV; 01-28-2020 at 02:04 PM.

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

    Re: SMALL function to exclude zero values?

    You are going to have to use an array formula. For the sake of example, the range is A2:A20. Then the formula is:

    =SMALL(IF(A2:A20<>0,A2:A20,FALSE),3)

    ...confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer.

    Also see this wiki: http://www.utteraccess.com/wiki/Array_Formulas
    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 Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: SMALL function to exclude zero values?

    Quote Originally Posted by dflak View Post
    You are going to have to use an array formula. . . .
    There's a way to do this which doesn't require array formula entry, just longer, less efficient formulas.

    =SMALL(INDEX(range+(range=0)*1E300,0),n)

    will return the nth smallest value from range ignoring zeros without needing array formula entry.

    FWIW, if Excel Online's spilled formula semantics would eventually become desktop Excel's spilled formula semantics, array formula entry may not be needed much longer. In my own testing, only IF, TRANSPOSE, MINVERSE and MMULT calls require array formula entry most of the time. Any expression involving only comparisons and arithmetic, such as the one above, can be put inside INDEX(...,0) or INDEX(...,0,0) to avoid array formula entry.

    That said, using array formulas for this is more efficient, Excel performs fewer internal calculations to produce the result.

  5. #5
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: SMALL function to exclude zero values?

    Quote Originally Posted by TME View Post
    I am using the SMALL formula . . . negative numbers and positive numbers are both OK to display, just not zeros. . . .
    If you were willing to use 2 additional cells with formulas, with ranked results beginning in X5,

    X1: =COUNTIF(range,"<0")
    X2: =COUNTIF(range."=0")

    SORRY, CORRECTION:
    X5: =SMALL(range,ROWS(X$5:X5)+(ROWS(X$5:X5)>X$1)*X$2)

    Fill X5 down as far as needed. FWLIW, I believe this is more efficient for this particular task than the array formulas provided.
    Last edited by hrlngrv; 01-28-2020 at 06:25 PM.

  6. #6
    Forum Expert BMV's Avatar
    Join Date
    01-13-2020
    Location
    St-Petersburg, Russia
    MS-Off Ver
    2013-2016
    Posts
    1,329

    Re: SMALL function to exclude zero values?

    hrlngrv, The array formulas is not worse then others and problem not because of array and because of not correct usage.

  7. #7
    Registered User
    Join Date
    01-28-2020
    Location
    Montgomery, Alabama
    MS-Off Ver
    Office 365
    Posts
    9

    Re: SMALL function to exclude zero values?

    Thank you so much, it worked! I appreciate everyone's helpful and timely responses. Thanks again!

  8. #8
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: SMALL function to exclude zero values?

    Quote Originally Posted by BMV View Post
    . . . The array formulas is not worse then others . . .
    Yeah, I botched the X5 formula. Fixed now.

    Thing is, your array formula (corrected to allow for negative values) =SMALL(IF(range<>0,range),1) is very efficient because the IF call replaces zero values with FALSE, and SMALL ignores those values. With N total items in range, and Z zero values, 2N - Z comparisons to get the result.

    Thing is, if this formula were repeated in N - Z cells to produce the ranked (ascending sorted nonzero) values from range, the formula above would involve (N - Z)(2N - Z) comparisons because every formula would perform the same range<>0 comparisons. My 2-extra-cells approach performs 2N comparisons in X1 and X2 together to handle figuring out negatives and zeros. The X5 formula performs N + 1 comparisons, so N - Z such formulas perform (N - Z)(N + 1) comparisons. (N - Z)(N + 1) + 2N < (N - Z)(2N - Z) when N is significantly larger than Z.

    When there are relatively many zeros in range, your array formula would be more efficient. Otherwise, my 2-extra-cells approach would be more efficient. None of which may matter if the values in range seldom change, in which case efficiency becomes far less important than clarity. That raises the question: are array formulas clear? Depends on who'd need to maintain the workbook.

  9. #9
    Registered User
    Join Date
    01-28-2020
    Location
    Montgomery, Alabama
    MS-Off Ver
    Office 365
    Posts
    9

    Question Re: SMALL function to exclude zero values?

    OK I need to refine my question a bit. I've attached an example. I would like to ignore zeros in other columns, not the data being ranked. I've been trying to use IF statements to account for this but keep getting formula errors. Please see attached.
    Attached Files Attached Files

  10. #10
    Forum Expert
    Join Date
    07-06-2004
    Location
    Northern California
    MS-Off Ver
    2K, 2003, 2010, O365
    Posts
    1,490

    Re: SMALL function to exclude zero values?

    Try

    D28: =LARGE(INDEX($D$6:$D$22-($B$6:$B$22=0)*($C$6:$C$22=0)*1E+300,0),A28)

    D43: =SMALL(INDEX($D$6:$D$22+($B$6:$B$22=0)*($C$6:$C$22=0)*1E+300,0),A43)

    Separately fill each down as far as needed. They return -1E300 and 1E300, respectively, when you've exhausted your data.

    Or, if you'd be willing to use 3 extra cells,

    D1: =COUNTIF(D6:D22,"<0")
    D2: =COUNTIFS(B6:B22,0,C6:C22,0)
    D3: =ROWS(D6:D22)-D1-D2

    D28: =LARGE($D$6:$D$22,A28+(A28>D$3)*D$2)

    D43: =SMALL($D$6:$D$22,A43+(A43>D$1)*D$2)

    Again, separately fill D28 and D43 down as far as needed. They return #NUM! when you've exhausted your data.
    Last edited by AliGW; 01-31-2020 at 04:18 AM. Reason: Please don't quote unnecessarily!

  11. #11
    Forum Expert
    Join Date
    02-19-2013
    Location
    India
    MS-Off Ver
    07/16
    Posts
    2,386

    Re: SMALL function to exclude zero values?

    Hello TME, copy paste below in D28 then hold ctrl+shift and Enter to make it array formula and drag down
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by hemesh; 01-29-2020 at 08:08 PM.
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    WANT TO SAY THANKS, HIT ADD REPUTATION (*) AT THE BOTTOM LEFT CORNER OF THE POST

    More we learn about excel, more it shows us, how less we know about it.

    for chemistry
    https://www.youtube.com/c/chemistrybyshivaansh

  12. #12
    Registered User
    Join Date
    01-28-2020
    Location
    Montgomery, Alabama
    MS-Off Ver
    Office 365
    Posts
    9

    Re: SMALL function to exclude zero values?

    So I used hemesh's formula and it seems to work great in identifying the correct number of zero values. Now, I need to be able to list the corresponding market name next to the matching values. My index formula has some problems in a couple of cases. Please see column F in the attached.
    Attached Files Attached Files

  13. #13
    Forum Expert
    Join Date
    02-19-2013
    Location
    India
    MS-Off Ver
    07/16
    Posts
    2,386

    Re: SMALL function to exclude zero values?

    Hello TMS,
    Thanks for the reply
    you could copy paste below in F28 and hit ctrl+shift+enter to make it array
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    01-28-2020
    Location
    Montgomery, Alabama
    MS-Off Ver
    Office 365
    Posts
    9

    Re: SMALL function to exclude zero values?

    Wow! I cannot express how much I appreciate your help! Thank you, thank you so much! I could not have done this without your help.

  15. #15
    Forum Expert
    Join Date
    02-19-2013
    Location
    India
    MS-Off Ver
    07/16
    Posts
    2,386

    Re: SMALL function to exclude zero values?

    @ TME, thanks for the response and Rep given and we are here to help and learn too.


    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    To Mark the thread as solved Go to Thread tools and mark as solved.

    If someone helps in Solving your query, you can Say Thank by clicking Add Reputation Icon in bottom left corner of their post

    More we learn about excel, more it shows us, how less we know about it.

  16. #16
    Registered User
    Join Date
    01-28-2020
    Location
    Montgomery, Alabama
    MS-Off Ver
    Office 365
    Posts
    9

    Re: SMALL function to exclude zero values?

    While the formula worked for the sample data set given, when I applied the formula to my full data set, which contains a lot more zero value situations, the formula stopped working correctly. I'm not sure what the -5 reference refers to and am wondering if that could be the issue. My formulas are tied to data from a pivot table and my formulas have to be dynamic and work for constantly changing scenarios. Thanks for your help.

  17. #17
    Forum Expert
    Join Date
    02-19-2013
    Location
    India
    MS-Off Ver
    07/16
    Posts
    2,386

    Re: SMALL function to exclude zero values?

    @ TMS have you changed the references according to your data !
    Row(D6:D22) gives row number from 6,7,8 to 22 now -5 will change it to 1,2,3,4 and so on and this will be the row number for index
    Hope this helps

  18. #18
    Registered User
    Join Date
    01-28-2020
    Location
    Montgomery, Alabama
    MS-Off Ver
    Office 365
    Posts
    9

    Re: SMALL function to exclude zero values?

    hemesh, yes I changed the references to reflect my data set. When I copied the formula and applied it to the sample worksheet it worked fine. But when I copied it in my actual file and changed the references to reflect my real data set it gave incorrect market names. I did this numerous times and checked my references. I don't understand why it wouldn't work the same with a larger data set.

  19. #19
    Forum Expert
    Join Date
    02-19-2013
    Location
    India
    MS-Off Ver
    07/16
    Posts
    2,386

    Re: SMALL function to exclude zero values?

    kindly upload a sample book with atleast 15-20 rows of data to work with having no sensitive information showing the incorrect results

  20. #20
    Registered User
    Join Date
    01-28-2020
    Location
    Montgomery, Alabama
    MS-Off Ver
    Office 365
    Posts
    9

    Re: SMALL function to exclude zero values?

    I added more data to simulate the file I'm working on. These are the same rows and columns used in my file. I hid blank rows for screen space. Column E shows the calculated results. Not sure why the additional rows would make a difference. Thanks for your help.
    Attached Files Attached Files

  21. #21
    Forum Expert
    Join Date
    02-19-2013
    Location
    India
    MS-Off Ver
    07/16
    Posts
    2,386

    Re: SMALL function to exclude zero values?

    hello TME, you just needed to change 5 to 15 as your data is started from row 16 (16-15 will give you row number one for index )
    use below
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  22. #22
    Registered User
    Join Date
    01-28-2020
    Location
    Montgomery, Alabama
    MS-Off Ver
    Office 365
    Posts
    9

    Re: SMALL function to exclude zero values?

    hemesh, thanks for explaining; I didn't understand that part of the formula. Now it makes sense and my formulas are PERFECT. Many thanks!

  23. #23
    Forum Expert
    Join Date
    02-19-2013
    Location
    India
    MS-Off Ver
    07/16
    Posts
    2,386

    Re: SMALL function to exclude zero values?

    Thanks for the feedback and I am glad I could help you

+ 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] Using the Small function to update corresponding values
    By virencm in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 03-02-2019, 07:29 AM
  2. [SOLVED] Using the small function to update corresponding values
    By virencm in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 03-01-2019, 10:12 PM
  3. [SOLVED] Using the LARGE function to exclude duplicate values
    By Gregbaron in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 01-05-2017, 04:05 PM
  4. [SOLVED] Exclude Cells with Zero from Complicated SMALL Formula
    By Phillycheese5 in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 01-20-2016, 06:54 PM
  5. [SOLVED] Help with IF function, small, exclude zero's, other
    By MWORSHAM in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 12-31-2012, 01:38 AM
  6. Use criteria for values in range for small function
    By like2hike in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-21-2006, 12:15 PM
  7. What function to select the last 3 small values from a list ?
    By Eric in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-31-2005, 07:20 AM

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