+ Reply to Thread
Results 1 to 14 of 14

Sort table with smallest to largest value with SMALL() and duplicate sorting values

  1. #1
    Registered User
    Join Date
    10-15-2019
    Location
    Europe
    MS-Off Ver
    Office 2016
    Posts
    4

    Sort table with smallest to largest value with SMALL() and duplicate sorting values

    Hello friends,

    I would like to ask for your help. :-)

    I am trying to sort a table in ascending order with a formula in Excel 2016.
    Certainly, I am aware that there are many ways to do this easily without a formula, but in this case I do need the formula-way.

    My situation is that I have a column with numerical values (height) an a corresponding column with people's names.
    So far my approach is to create a new sorted table next to the original unsorted table, using the height column (sorted with SMALL()) as an anchor for an INDEX(MATCH()) column to add the names next to it.
    However, my problem is that two people have the same height and the INDEX(MATCH()) combo only gives me the name of the first person of the duplicate height.

    I have attached a workbook to show my problem and would greatly appreciate your inputs! :-)

    All the best, stay healthy!
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Sort table with smallest to largest value with SMALL() and duplicate sorting values

    c3 =B3+Row()/10000000 and drag down (yellow cells).

    After that you can use the orignal formula

    see the green cells in the attached file.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  3. #3
    Registered User
    Join Date
    10-15-2019
    Location
    Europe
    MS-Off Ver
    Office 2016
    Posts
    4

    Re: Sort table with smallest to largest value with SMALL() and duplicate sorting values

    Quote Originally Posted by oeldere View Post
    c3 =B3+Row()/10000000

    Hello oledere,

    Am I understanding correctly that your intention with your formula given here is to add just the tiniest little difference to the values of my height column in order to make them all unique?
    That is brilliant! Thank you very much for your help!

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,077

    Re: Sort table with smallest to largest value with SMALL() and duplicate sorting values

    Another option, without helper cells
    =INDEX($A$3:$A$6,AGGREGATE(15,6,(ROW($A$3:$A$6)-ROW($A$3)+1)/($B$3:$B$6=G3),COUNTIF(G$3:G3,G3)))

  5. #5
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Sort table with smallest to largest value with SMALL() and duplicate sorting values

    @El_Presidente

    Yes, that is the idea.

    Please also reply on the solution of Fluff13

    Glad I could help.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  6. #6
    Registered User
    Join Date
    10-15-2019
    Location
    Europe
    MS-Off Ver
    Office 2016
    Posts
    4

    Re: Sort table with smallest to largest value with SMALL() and duplicate sorting values

    Quote Originally Posted by Fluff13 View Post
    Another option, without helper cells
    =INDEX($A$3:$A$6,AGGREGATE(15,6,(ROW($A$3:$A$6)-ROW($A$3)+1)/($B$3:$B$6=G3),COUNTIF(G$3:G3,G3)))
    Thank you for your answer, Fluff13!
    Your formula works perfectly, but I struggle with understanding it completely, to be honest.
    Would you mind explaining the logic behind the following parts to me?

    =INDEX($A$3:$A$6,AGGREGATE(15,6,(ROW($A$3:$A$6)-ROW($A$3)+1)/($B$3:$B$6=G3),COUNTIF(G$3:G3,G3)))
    I get that you are defining the array here, but the method I cannot quite grasp.


    =INDEX($A$3:$A$6,AGGREGATE(15,6,(ROW($A$3:$A$6)-ROW($A$3)+1)/($B$3:$B$6=G3),COUNTIF(G$3:G3,G3)))
    I get that you are defining the k-smallest value, but still not quite the full story as to how it fits into the logic of the complete formula.

    I'd greatly appreciate an explanation since I'm really into learning Excel and not just the "copy-paste-pray" method.

  7. #7
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,077

    Re: Sort table with smallest to largest value with SMALL() and duplicate sorting values

    This part returns an array of numbers, in this case {1,2,3,4}
    (ROW($A$3:$A$6)-ROW($A$3)+1)

    then this returns an array of true or false, depending on whether the value in B = G3
    ($B$3:$B$6=G3)

    we then divide the two arrays where true=1 & false =0 which will give an array like {#DIV/0!,2,3,#DIV/0!}

    For H3 the countif returns 1, so we get the 1st smallest value & then in H4 the countif will return 2, so we get the 2nd smallest.

    The best way to see what is happening is tho use the "Evaluate Formula" option on the formula tab.

  8. #8
    Registered User
    Join Date
    10-15-2019
    Location
    Europe
    MS-Off Ver
    Office 2016
    Posts
    4

    Re: Sort table with smallest to largest value with SMALL() and duplicate sorting values

    Thank you for your explanation, Fluff13!

    Today I got the time to really dig into it and undestood how your formula works.

    My question has now received two great answers (by oldere, Fluff13) and I am closing this thread as "solved".

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,410

    Re: Sort table with smallest to largest value with SMALL() and duplicate sorting values

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  10. #10
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,077

    Re: Sort table with smallest to largest value with SMALL() and duplicate sorting values

    Thank you for your explanation, Fluff13!
    You're welcome & thanks for the feedback.

  11. #11
    Forum Expert
    Join Date
    09-07-2014
    Location
    Israel
    MS-Off Ver
    office 365 for MAC
    Posts
    3,105

    Re: Sort table with smallest to largest value with SMALL() and duplicate sorting values

    Quote Originally Posted by Fluff13 View Post
    Another option, without helper cells
    =INDEX($A$3:$A$6,AGGREGATE(15,6,(ROW($A$3:$A$6)-ROW($A$3)+1)/($B$3:$B$6=G3),COUNTIF(G$3:G3,G3)))
    Hi Fluff13,
    Is your formula supposed to be applied in cell H3 and down? For some reason it doesnt work for me.
    Also not in array type.
    Can you guess why?

  12. #12
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,077

    Re: Sort table with smallest to largest value with SMALL() and duplicate sorting values

    If your using 2007, then it won't work as the Aggregate function only came into being with 2010.

  13. #13
    Forum Expert
    Join Date
    09-07-2014
    Location
    Israel
    MS-Off Ver
    office 365 for MAC
    Posts
    3,105

    Re: Sort table with smallest to largest value with SMALL() and duplicate sorting values

    OK that explains it. Thanks.

  14. #14
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,077

    Re: Sort table with smallest to largest value with SMALL() and duplicate sorting values

    You're welcome.

+ 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] Sort Last Pivot table column Largest to Smallest
    By 3345james in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-06-2018, 04:55 PM
  2. [SOLVED] Why is the format table not sorting the date by smallest to largest?
    By sovietchild in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 08-15-2017, 08:56 PM
  3. Replies: 7
    Last Post: 06-20-2016, 08:37 AM
  4. VBA code to set sort the values several pivot tables from largest to smallest
    By Tanner2004 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-14-2016, 02:43 PM
  5. Replies: 1
    Last Post: 04-16-2015, 06:29 PM
  6. Sort largest to smallest - VBA
    By Ricardo Mass in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-12-2013, 09:05 AM
  7. Sorting Largest To Smallest
    By all4excel in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-24-2007, 10:30 PM

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