Excel - Sort by formula when there are duplicate values












0














My data will change, therefore I am using dynamic lists. Sorting needs to be dynamic as well. I do not want to click on the built in sort function.



I'm sorting dynamic data by formula, but it fails when the sort data is the same. For example:



A B
Marham 240
Sigonella 400
Toulon 400
Ghedi 150
Lajes 2000
Nordholz 400



Sorting by column B and returning column A values, the result should be:



Lajes 2000
Sigonella 400
Toulon 400
Nordholz 400
Marham 240
Ghedi 150



Note: I don't care about the order of the duplicated values among themselves (the "400"s).



With this formula:
{=INDEX($A$1:$A$6, MATCH(SMALL(COUNTIF($B$1:$B$6, "<"&$B$1:$B$6), ROW(1:1)), COUNTIF($B$1:$B$6, "<"&$B$1:$B$6), 0))}



The results are:



Lajes 2000
Sigonella 400
Sigonella 400
Sigonella 400
Marham 240
Ghedi 150



The MATCH is tripping me up. How do I get around this?










share|improve this question





























    0














    My data will change, therefore I am using dynamic lists. Sorting needs to be dynamic as well. I do not want to click on the built in sort function.



    I'm sorting dynamic data by formula, but it fails when the sort data is the same. For example:



    A B
    Marham 240
    Sigonella 400
    Toulon 400
    Ghedi 150
    Lajes 2000
    Nordholz 400



    Sorting by column B and returning column A values, the result should be:



    Lajes 2000
    Sigonella 400
    Toulon 400
    Nordholz 400
    Marham 240
    Ghedi 150



    Note: I don't care about the order of the duplicated values among themselves (the "400"s).



    With this formula:
    {=INDEX($A$1:$A$6, MATCH(SMALL(COUNTIF($B$1:$B$6, "<"&$B$1:$B$6), ROW(1:1)), COUNTIF($B$1:$B$6, "<"&$B$1:$B$6), 0))}



    The results are:



    Lajes 2000
    Sigonella 400
    Sigonella 400
    Sigonella 400
    Marham 240
    Ghedi 150



    The MATCH is tripping me up. How do I get around this?










    share|improve this question



























      0












      0








      0







      My data will change, therefore I am using dynamic lists. Sorting needs to be dynamic as well. I do not want to click on the built in sort function.



      I'm sorting dynamic data by formula, but it fails when the sort data is the same. For example:



      A B
      Marham 240
      Sigonella 400
      Toulon 400
      Ghedi 150
      Lajes 2000
      Nordholz 400



      Sorting by column B and returning column A values, the result should be:



      Lajes 2000
      Sigonella 400
      Toulon 400
      Nordholz 400
      Marham 240
      Ghedi 150



      Note: I don't care about the order of the duplicated values among themselves (the "400"s).



      With this formula:
      {=INDEX($A$1:$A$6, MATCH(SMALL(COUNTIF($B$1:$B$6, "<"&$B$1:$B$6), ROW(1:1)), COUNTIF($B$1:$B$6, "<"&$B$1:$B$6), 0))}



      The results are:



      Lajes 2000
      Sigonella 400
      Sigonella 400
      Sigonella 400
      Marham 240
      Ghedi 150



      The MATCH is tripping me up. How do I get around this?










      share|improve this question















      My data will change, therefore I am using dynamic lists. Sorting needs to be dynamic as well. I do not want to click on the built in sort function.



      I'm sorting dynamic data by formula, but it fails when the sort data is the same. For example:



      A B
      Marham 240
      Sigonella 400
      Toulon 400
      Ghedi 150
      Lajes 2000
      Nordholz 400



      Sorting by column B and returning column A values, the result should be:



      Lajes 2000
      Sigonella 400
      Toulon 400
      Nordholz 400
      Marham 240
      Ghedi 150



      Note: I don't care about the order of the duplicated values among themselves (the "400"s).



      With this formula:
      {=INDEX($A$1:$A$6, MATCH(SMALL(COUNTIF($B$1:$B$6, "<"&$B$1:$B$6), ROW(1:1)), COUNTIF($B$1:$B$6, "<"&$B$1:$B$6), 0))}



      The results are:



      Lajes 2000
      Sigonella 400
      Sigonella 400
      Sigonella 400
      Marham 240
      Ghedi 150



      The MATCH is tripping me up. How do I get around this?







      microsoft-excel-2010 sorting






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 1 '16 at 16:45









      root

      2,31251535




      2,31251535










      asked Apr 1 '16 at 14:28









      mechengr02

      36211




      36211






















          4 Answers
          4






          active

          oldest

          votes


















          0














          Here's what I came up with... It's not exactly what I was looking for...but it worked.



          Using the same data above, I changed the INDEX to return the score instead of the bases:



          {=INDEX($B$1:$B$6, MATCH(SMALL(COUNTIF($B$1:$B$6, "<"&$B$1:$B$6), ROW(1:1)), COUNTIF($B$1:$B$6, "<"&$B$1:$B$6), 0))}



          Then to return the bases, I used this formula which returns multiple matching values:



          {=index(A$1:A$6,small(if(b$1:b$6=b1,row(b$1:b$6)),countif(b$1:b$6,b1)))}



          I'd still like to get the original formula working on its own, if anyone has a suggestion.






          share|improve this answer





























            0














            You can get around duplicates by adding a hidden column C, where you add to your values some very little numbers, small enough not to be obtainable by other means and not to interfere with the original values, which let you differentiate between duplicates, e.g.



              A          B          C
            Marham 240 240,0001
            Sigonella 400 400,0002
            Toulon 400 400,0003
            Ghedi 150 150,0004
            Lajes 2000 2000,0005
            Nordholz 400 400,0006


            Then you just sort by the values in column C



            Alternatively, if you don't want any hidden columns, you can put the values in like this:



              A            B
            Marham 240,0001
            Sigonella 400,0002
            Toulon 400,0003
            Ghedi 150,0004
            Lajes 2000,0005
            Nordholz 400,0006


            but format the fields to display numeric values with 0 digit precision, so excel keeps your detailed values but displays them as:



              A          B
            Marham 240
            Sigonella 400
            Toulon 400
            Ghedi 150
            Lajes 2000
            Nordholz 400





            share|improve this answer































              -1














              I know this was forever ago, but the formulas in the other answers didn't work for me. However, I did get it to work with a few minor modifications:



              {=INDEX($A$1:$A$7,SMALL(IF(B$1:B$6=B1,ROW(B$1:B$6)),COUNTIF(B1:B$6,B1)))}





              share|improve this answer























              • You might add some detail to explain what this does as well. Fix the formatting of the code too.
                – Pimp Juice IT
                Jul 8 '17 at 15:47



















              -3














              How about =sort(a2:b7,2,true) in cell C2?






              share|improve this answer























              • While this may answer the question, it would be a better answer if you could provide some explanation why it does so.
                – DavidPostill
                Dec 20 '17 at 21:46










              • I was not able to find the sort function in the eXcel list...
                – Hastur
                Dec 20 '17 at 22:38











              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "3"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1060171%2fexcel-sort-by-formula-when-there-are-duplicate-values%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              4 Answers
              4






              active

              oldest

              votes








              4 Answers
              4






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              Here's what I came up with... It's not exactly what I was looking for...but it worked.



              Using the same data above, I changed the INDEX to return the score instead of the bases:



              {=INDEX($B$1:$B$6, MATCH(SMALL(COUNTIF($B$1:$B$6, "<"&$B$1:$B$6), ROW(1:1)), COUNTIF($B$1:$B$6, "<"&$B$1:$B$6), 0))}



              Then to return the bases, I used this formula which returns multiple matching values:



              {=index(A$1:A$6,small(if(b$1:b$6=b1,row(b$1:b$6)),countif(b$1:b$6,b1)))}



              I'd still like to get the original formula working on its own, if anyone has a suggestion.






              share|improve this answer


























                0














                Here's what I came up with... It's not exactly what I was looking for...but it worked.



                Using the same data above, I changed the INDEX to return the score instead of the bases:



                {=INDEX($B$1:$B$6, MATCH(SMALL(COUNTIF($B$1:$B$6, "<"&$B$1:$B$6), ROW(1:1)), COUNTIF($B$1:$B$6, "<"&$B$1:$B$6), 0))}



                Then to return the bases, I used this formula which returns multiple matching values:



                {=index(A$1:A$6,small(if(b$1:b$6=b1,row(b$1:b$6)),countif(b$1:b$6,b1)))}



                I'd still like to get the original formula working on its own, if anyone has a suggestion.






                share|improve this answer
























                  0












                  0








                  0






                  Here's what I came up with... It's not exactly what I was looking for...but it worked.



                  Using the same data above, I changed the INDEX to return the score instead of the bases:



                  {=INDEX($B$1:$B$6, MATCH(SMALL(COUNTIF($B$1:$B$6, "<"&$B$1:$B$6), ROW(1:1)), COUNTIF($B$1:$B$6, "<"&$B$1:$B$6), 0))}



                  Then to return the bases, I used this formula which returns multiple matching values:



                  {=index(A$1:A$6,small(if(b$1:b$6=b1,row(b$1:b$6)),countif(b$1:b$6,b1)))}



                  I'd still like to get the original formula working on its own, if anyone has a suggestion.






                  share|improve this answer












                  Here's what I came up with... It's not exactly what I was looking for...but it worked.



                  Using the same data above, I changed the INDEX to return the score instead of the bases:



                  {=INDEX($B$1:$B$6, MATCH(SMALL(COUNTIF($B$1:$B$6, "<"&$B$1:$B$6), ROW(1:1)), COUNTIF($B$1:$B$6, "<"&$B$1:$B$6), 0))}



                  Then to return the bases, I used this formula which returns multiple matching values:



                  {=index(A$1:A$6,small(if(b$1:b$6=b1,row(b$1:b$6)),countif(b$1:b$6,b1)))}



                  I'd still like to get the original formula working on its own, if anyone has a suggestion.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Apr 4 '16 at 18:49









                  mechengr02

                  36211




                  36211

























                      0














                      You can get around duplicates by adding a hidden column C, where you add to your values some very little numbers, small enough not to be obtainable by other means and not to interfere with the original values, which let you differentiate between duplicates, e.g.



                        A          B          C
                      Marham 240 240,0001
                      Sigonella 400 400,0002
                      Toulon 400 400,0003
                      Ghedi 150 150,0004
                      Lajes 2000 2000,0005
                      Nordholz 400 400,0006


                      Then you just sort by the values in column C



                      Alternatively, if you don't want any hidden columns, you can put the values in like this:



                        A            B
                      Marham 240,0001
                      Sigonella 400,0002
                      Toulon 400,0003
                      Ghedi 150,0004
                      Lajes 2000,0005
                      Nordholz 400,0006


                      but format the fields to display numeric values with 0 digit precision, so excel keeps your detailed values but displays them as:



                        A          B
                      Marham 240
                      Sigonella 400
                      Toulon 400
                      Ghedi 150
                      Lajes 2000
                      Nordholz 400





                      share|improve this answer




























                        0














                        You can get around duplicates by adding a hidden column C, where you add to your values some very little numbers, small enough not to be obtainable by other means and not to interfere with the original values, which let you differentiate between duplicates, e.g.



                          A          B          C
                        Marham 240 240,0001
                        Sigonella 400 400,0002
                        Toulon 400 400,0003
                        Ghedi 150 150,0004
                        Lajes 2000 2000,0005
                        Nordholz 400 400,0006


                        Then you just sort by the values in column C



                        Alternatively, if you don't want any hidden columns, you can put the values in like this:



                          A            B
                        Marham 240,0001
                        Sigonella 400,0002
                        Toulon 400,0003
                        Ghedi 150,0004
                        Lajes 2000,0005
                        Nordholz 400,0006


                        but format the fields to display numeric values with 0 digit precision, so excel keeps your detailed values but displays them as:



                          A          B
                        Marham 240
                        Sigonella 400
                        Toulon 400
                        Ghedi 150
                        Lajes 2000
                        Nordholz 400





                        share|improve this answer


























                          0












                          0








                          0






                          You can get around duplicates by adding a hidden column C, where you add to your values some very little numbers, small enough not to be obtainable by other means and not to interfere with the original values, which let you differentiate between duplicates, e.g.



                            A          B          C
                          Marham 240 240,0001
                          Sigonella 400 400,0002
                          Toulon 400 400,0003
                          Ghedi 150 150,0004
                          Lajes 2000 2000,0005
                          Nordholz 400 400,0006


                          Then you just sort by the values in column C



                          Alternatively, if you don't want any hidden columns, you can put the values in like this:



                            A            B
                          Marham 240,0001
                          Sigonella 400,0002
                          Toulon 400,0003
                          Ghedi 150,0004
                          Lajes 2000,0005
                          Nordholz 400,0006


                          but format the fields to display numeric values with 0 digit precision, so excel keeps your detailed values but displays them as:



                            A          B
                          Marham 240
                          Sigonella 400
                          Toulon 400
                          Ghedi 150
                          Lajes 2000
                          Nordholz 400





                          share|improve this answer














                          You can get around duplicates by adding a hidden column C, where you add to your values some very little numbers, small enough not to be obtainable by other means and not to interfere with the original values, which let you differentiate between duplicates, e.g.



                            A          B          C
                          Marham 240 240,0001
                          Sigonella 400 400,0002
                          Toulon 400 400,0003
                          Ghedi 150 150,0004
                          Lajes 2000 2000,0005
                          Nordholz 400 400,0006


                          Then you just sort by the values in column C



                          Alternatively, if you don't want any hidden columns, you can put the values in like this:



                            A            B
                          Marham 240,0001
                          Sigonella 400,0002
                          Toulon 400,0003
                          Ghedi 150,0004
                          Lajes 2000,0005
                          Nordholz 400,0006


                          but format the fields to display numeric values with 0 digit precision, so excel keeps your detailed values but displays them as:



                            A          B
                          Marham 240
                          Sigonella 400
                          Toulon 400
                          Ghedi 150
                          Lajes 2000
                          Nordholz 400






                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Oct 23 '16 at 13:35

























                          answered Oct 23 '16 at 12:54









                          zioming

                          11




                          11























                              -1














                              I know this was forever ago, but the formulas in the other answers didn't work for me. However, I did get it to work with a few minor modifications:



                              {=INDEX($A$1:$A$7,SMALL(IF(B$1:B$6=B1,ROW(B$1:B$6)),COUNTIF(B1:B$6,B1)))}





                              share|improve this answer























                              • You might add some detail to explain what this does as well. Fix the formatting of the code too.
                                – Pimp Juice IT
                                Jul 8 '17 at 15:47
















                              -1














                              I know this was forever ago, but the formulas in the other answers didn't work for me. However, I did get it to work with a few minor modifications:



                              {=INDEX($A$1:$A$7,SMALL(IF(B$1:B$6=B1,ROW(B$1:B$6)),COUNTIF(B1:B$6,B1)))}





                              share|improve this answer























                              • You might add some detail to explain what this does as well. Fix the formatting of the code too.
                                – Pimp Juice IT
                                Jul 8 '17 at 15:47














                              -1












                              -1








                              -1






                              I know this was forever ago, but the formulas in the other answers didn't work for me. However, I did get it to work with a few minor modifications:



                              {=INDEX($A$1:$A$7,SMALL(IF(B$1:B$6=B1,ROW(B$1:B$6)),COUNTIF(B1:B$6,B1)))}





                              share|improve this answer














                              I know this was forever ago, but the formulas in the other answers didn't work for me. However, I did get it to work with a few minor modifications:



                              {=INDEX($A$1:$A$7,SMALL(IF(B$1:B$6=B1,ROW(B$1:B$6)),COUNTIF(B1:B$6,B1)))}






                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Dec 20 '17 at 22:17









                              Hastur

                              13.1k53266




                              13.1k53266










                              answered Jul 8 '17 at 15:27









                              RansomV

                              1




                              1












                              • You might add some detail to explain what this does as well. Fix the formatting of the code too.
                                – Pimp Juice IT
                                Jul 8 '17 at 15:47


















                              • You might add some detail to explain what this does as well. Fix the formatting of the code too.
                                – Pimp Juice IT
                                Jul 8 '17 at 15:47
















                              You might add some detail to explain what this does as well. Fix the formatting of the code too.
                              – Pimp Juice IT
                              Jul 8 '17 at 15:47




                              You might add some detail to explain what this does as well. Fix the formatting of the code too.
                              – Pimp Juice IT
                              Jul 8 '17 at 15:47











                              -3














                              How about =sort(a2:b7,2,true) in cell C2?






                              share|improve this answer























                              • While this may answer the question, it would be a better answer if you could provide some explanation why it does so.
                                – DavidPostill
                                Dec 20 '17 at 21:46










                              • I was not able to find the sort function in the eXcel list...
                                – Hastur
                                Dec 20 '17 at 22:38
















                              -3














                              How about =sort(a2:b7,2,true) in cell C2?






                              share|improve this answer























                              • While this may answer the question, it would be a better answer if you could provide some explanation why it does so.
                                – DavidPostill
                                Dec 20 '17 at 21:46










                              • I was not able to find the sort function in the eXcel list...
                                – Hastur
                                Dec 20 '17 at 22:38














                              -3












                              -3








                              -3






                              How about =sort(a2:b7,2,true) in cell C2?






                              share|improve this answer














                              How about =sort(a2:b7,2,true) in cell C2?







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Dec 20 '17 at 22:37









                              Hastur

                              13.1k53266




                              13.1k53266










                              answered Dec 20 '17 at 20:44









                              Sam

                              1




                              1












                              • While this may answer the question, it would be a better answer if you could provide some explanation why it does so.
                                – DavidPostill
                                Dec 20 '17 at 21:46










                              • I was not able to find the sort function in the eXcel list...
                                – Hastur
                                Dec 20 '17 at 22:38


















                              • While this may answer the question, it would be a better answer if you could provide some explanation why it does so.
                                – DavidPostill
                                Dec 20 '17 at 21:46










                              • I was not able to find the sort function in the eXcel list...
                                – Hastur
                                Dec 20 '17 at 22:38
















                              While this may answer the question, it would be a better answer if you could provide some explanation why it does so.
                              – DavidPostill
                              Dec 20 '17 at 21:46




                              While this may answer the question, it would be a better answer if you could provide some explanation why it does so.
                              – DavidPostill
                              Dec 20 '17 at 21:46












                              I was not able to find the sort function in the eXcel list...
                              – Hastur
                              Dec 20 '17 at 22:38




                              I was not able to find the sort function in the eXcel list...
                              – Hastur
                              Dec 20 '17 at 22:38


















                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Super User!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.





                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                              Please pay close attention to the following guidance:


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1060171%2fexcel-sort-by-formula-when-there-are-duplicate-values%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Probability when a professor distributes a quiz and homework assignment to a class of n students.

                              Aardman Animations

                              Are they similar matrix