Excel find bucket without nested IFs











up vote
0
down vote

favorite












I have to separate my data in category, say for example:



Category    Minimum    Maximum
A -100 -20
B -20 0
C 0 +20
D +20 +100


So if one data point is -50, it belongs to Category A.



One solution is to use nested IFs:



=IF(A1<-20,"A",IF(A1<0,"B",IF(A1<20,"C","D")))


But when the number of categories increases it becomes quite messy. Is there a better way to achieve the same?










share|improve this question


























    up vote
    0
    down vote

    favorite












    I have to separate my data in category, say for example:



    Category    Minimum    Maximum
    A -100 -20
    B -20 0
    C 0 +20
    D +20 +100


    So if one data point is -50, it belongs to Category A.



    One solution is to use nested IFs:



    =IF(A1<-20,"A",IF(A1<0,"B",IF(A1<20,"C","D")))


    But when the number of categories increases it becomes quite messy. Is there a better way to achieve the same?










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have to separate my data in category, say for example:



      Category    Minimum    Maximum
      A -100 -20
      B -20 0
      C 0 +20
      D +20 +100


      So if one data point is -50, it belongs to Category A.



      One solution is to use nested IFs:



      =IF(A1<-20,"A",IF(A1<0,"B",IF(A1<20,"C","D")))


      But when the number of categories increases it becomes quite messy. Is there a better way to achieve the same?










      share|improve this question













      I have to separate my data in category, say for example:



      Category    Minimum    Maximum
      A -100 -20
      B -20 0
      C 0 +20
      D +20 +100


      So if one data point is -50, it belongs to Category A.



      One solution is to use nested IFs:



      =IF(A1<-20,"A",IF(A1<0,"B",IF(A1<20,"C","D")))


      But when the number of categories increases it becomes quite messy. Is there a better way to achieve the same?







      microsoft-excel worksheet-function






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Oct 19 '12 at 9:27









      assylias

      401313




      401313






















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          Assuming you have the table with categories in Y2:Y10 and the minimums in Z2:Z10 (with 20 not +20 and similar for all positive numbers) then you can use a LOOKUP formula



          =LOOKUP(A1,Y$2:Y$10,Z$2:Z$10)



          Assumes there are no gaps in the ranges, i.e. the maximum for each category is effectively assumed to be immediately beow the next minimum






          share|improve this answer





















          • You have inverted the 2 ranges in your formula, it should be =LOOKUP(A1,Z2:Z10,Y2,Y10) - otherwise it works fine, thanks.
            – assylias
            Oct 19 '12 at 9:56










          • Yes you are correct, apologies.
            – barry houdini
            Oct 19 '12 at 10:37


















          up vote
          0
          down vote













          Another solution could be using named ranges.



          I would modify your example to this:



          Category    Minimum    Maximum
          Cat_A -100 -20
          Cat_B -20 0
          Cat_C 0 +20
          Cat_D +20 +100


          Then mark the data from Cat_A to +100, and use Make from selection (On Formula Tab, Section Defined Names) - use make from left column.



          The you will get 4 named ranges Cat_A, Cat_B, Cat_C and Cat_D, which you can use in your workbook for i.e. conditional formatting, unsing Min(Cat_A) and Max(Cat_A) as limits.



          However, this solution is more an extention to the one of barry houdini.






          share|improve this answer




























            up vote
            0
            down vote













            I use this trick for equal data bucketing. Suppose you have data in A1:A100 range. Put this formula in B1:



            =MAX(ROUNDUP(PERCENTRANK($A$1:$A$100,A1) *4,0),1)


            Fill down the formula all across B column and you are done. The formula divides the range into 4 equal buckets and it returns the bucket number which the cell A1 falls into. The first bucket contains the lowest 25% of values.



            Adjust the number of buckets according to thy wish:



            =MAX(ROUNDUP(PERCENTRANK([Range],[OneCellOfTheRange]) *[NumberOfBuckets],0),1)


            The Advantage

            The advantage of this solution is that you do not have to worry about the min and max of each bucket. The min and max parameters will mysteriously adjust themselves keeping equal number of observation in each bucket.






            share|improve this answer





















              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',
              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%2f489824%2fexcel-find-bucket-without-nested-ifs%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              1
              down vote



              accepted










              Assuming you have the table with categories in Y2:Y10 and the minimums in Z2:Z10 (with 20 not +20 and similar for all positive numbers) then you can use a LOOKUP formula



              =LOOKUP(A1,Y$2:Y$10,Z$2:Z$10)



              Assumes there are no gaps in the ranges, i.e. the maximum for each category is effectively assumed to be immediately beow the next minimum






              share|improve this answer





















              • You have inverted the 2 ranges in your formula, it should be =LOOKUP(A1,Z2:Z10,Y2,Y10) - otherwise it works fine, thanks.
                – assylias
                Oct 19 '12 at 9:56










              • Yes you are correct, apologies.
                – barry houdini
                Oct 19 '12 at 10:37















              up vote
              1
              down vote



              accepted










              Assuming you have the table with categories in Y2:Y10 and the minimums in Z2:Z10 (with 20 not +20 and similar for all positive numbers) then you can use a LOOKUP formula



              =LOOKUP(A1,Y$2:Y$10,Z$2:Z$10)



              Assumes there are no gaps in the ranges, i.e. the maximum for each category is effectively assumed to be immediately beow the next minimum






              share|improve this answer





















              • You have inverted the 2 ranges in your formula, it should be =LOOKUP(A1,Z2:Z10,Y2,Y10) - otherwise it works fine, thanks.
                – assylias
                Oct 19 '12 at 9:56










              • Yes you are correct, apologies.
                – barry houdini
                Oct 19 '12 at 10:37













              up vote
              1
              down vote



              accepted







              up vote
              1
              down vote



              accepted






              Assuming you have the table with categories in Y2:Y10 and the minimums in Z2:Z10 (with 20 not +20 and similar for all positive numbers) then you can use a LOOKUP formula



              =LOOKUP(A1,Y$2:Y$10,Z$2:Z$10)



              Assumes there are no gaps in the ranges, i.e. the maximum for each category is effectively assumed to be immediately beow the next minimum






              share|improve this answer












              Assuming you have the table with categories in Y2:Y10 and the minimums in Z2:Z10 (with 20 not +20 and similar for all positive numbers) then you can use a LOOKUP formula



              =LOOKUP(A1,Y$2:Y$10,Z$2:Z$10)



              Assumes there are no gaps in the ranges, i.e. the maximum for each category is effectively assumed to be immediately beow the next minimum







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Oct 19 '12 at 9:36









              barry houdini

              9,90411320




              9,90411320












              • You have inverted the 2 ranges in your formula, it should be =LOOKUP(A1,Z2:Z10,Y2,Y10) - otherwise it works fine, thanks.
                – assylias
                Oct 19 '12 at 9:56










              • Yes you are correct, apologies.
                – barry houdini
                Oct 19 '12 at 10:37


















              • You have inverted the 2 ranges in your formula, it should be =LOOKUP(A1,Z2:Z10,Y2,Y10) - otherwise it works fine, thanks.
                – assylias
                Oct 19 '12 at 9:56










              • Yes you are correct, apologies.
                – barry houdini
                Oct 19 '12 at 10:37
















              You have inverted the 2 ranges in your formula, it should be =LOOKUP(A1,Z2:Z10,Y2,Y10) - otherwise it works fine, thanks.
              – assylias
              Oct 19 '12 at 9:56




              You have inverted the 2 ranges in your formula, it should be =LOOKUP(A1,Z2:Z10,Y2,Y10) - otherwise it works fine, thanks.
              – assylias
              Oct 19 '12 at 9:56












              Yes you are correct, apologies.
              – barry houdini
              Oct 19 '12 at 10:37




              Yes you are correct, apologies.
              – barry houdini
              Oct 19 '12 at 10:37












              up vote
              0
              down vote













              Another solution could be using named ranges.



              I would modify your example to this:



              Category    Minimum    Maximum
              Cat_A -100 -20
              Cat_B -20 0
              Cat_C 0 +20
              Cat_D +20 +100


              Then mark the data from Cat_A to +100, and use Make from selection (On Formula Tab, Section Defined Names) - use make from left column.



              The you will get 4 named ranges Cat_A, Cat_B, Cat_C and Cat_D, which you can use in your workbook for i.e. conditional formatting, unsing Min(Cat_A) and Max(Cat_A) as limits.



              However, this solution is more an extention to the one of barry houdini.






              share|improve this answer

























                up vote
                0
                down vote













                Another solution could be using named ranges.



                I would modify your example to this:



                Category    Minimum    Maximum
                Cat_A -100 -20
                Cat_B -20 0
                Cat_C 0 +20
                Cat_D +20 +100


                Then mark the data from Cat_A to +100, and use Make from selection (On Formula Tab, Section Defined Names) - use make from left column.



                The you will get 4 named ranges Cat_A, Cat_B, Cat_C and Cat_D, which you can use in your workbook for i.e. conditional formatting, unsing Min(Cat_A) and Max(Cat_A) as limits.



                However, this solution is more an extention to the one of barry houdini.






                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  Another solution could be using named ranges.



                  I would modify your example to this:



                  Category    Minimum    Maximum
                  Cat_A -100 -20
                  Cat_B -20 0
                  Cat_C 0 +20
                  Cat_D +20 +100


                  Then mark the data from Cat_A to +100, and use Make from selection (On Formula Tab, Section Defined Names) - use make from left column.



                  The you will get 4 named ranges Cat_A, Cat_B, Cat_C and Cat_D, which you can use in your workbook for i.e. conditional formatting, unsing Min(Cat_A) and Max(Cat_A) as limits.



                  However, this solution is more an extention to the one of barry houdini.






                  share|improve this answer












                  Another solution could be using named ranges.



                  I would modify your example to this:



                  Category    Minimum    Maximum
                  Cat_A -100 -20
                  Cat_B -20 0
                  Cat_C 0 +20
                  Cat_D +20 +100


                  Then mark the data from Cat_A to +100, and use Make from selection (On Formula Tab, Section Defined Names) - use make from left column.



                  The you will get 4 named ranges Cat_A, Cat_B, Cat_C and Cat_D, which you can use in your workbook for i.e. conditional formatting, unsing Min(Cat_A) and Max(Cat_A) as limits.



                  However, this solution is more an extention to the one of barry houdini.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Oct 19 '12 at 10:01









                  Jook

                  1,46021629




                  1,46021629






















                      up vote
                      0
                      down vote













                      I use this trick for equal data bucketing. Suppose you have data in A1:A100 range. Put this formula in B1:



                      =MAX(ROUNDUP(PERCENTRANK($A$1:$A$100,A1) *4,0),1)


                      Fill down the formula all across B column and you are done. The formula divides the range into 4 equal buckets and it returns the bucket number which the cell A1 falls into. The first bucket contains the lowest 25% of values.



                      Adjust the number of buckets according to thy wish:



                      =MAX(ROUNDUP(PERCENTRANK([Range],[OneCellOfTheRange]) *[NumberOfBuckets],0),1)


                      The Advantage

                      The advantage of this solution is that you do not have to worry about the min and max of each bucket. The min and max parameters will mysteriously adjust themselves keeping equal number of observation in each bucket.






                      share|improve this answer

























                        up vote
                        0
                        down vote













                        I use this trick for equal data bucketing. Suppose you have data in A1:A100 range. Put this formula in B1:



                        =MAX(ROUNDUP(PERCENTRANK($A$1:$A$100,A1) *4,0),1)


                        Fill down the formula all across B column and you are done. The formula divides the range into 4 equal buckets and it returns the bucket number which the cell A1 falls into. The first bucket contains the lowest 25% of values.



                        Adjust the number of buckets according to thy wish:



                        =MAX(ROUNDUP(PERCENTRANK([Range],[OneCellOfTheRange]) *[NumberOfBuckets],0),1)


                        The Advantage

                        The advantage of this solution is that you do not have to worry about the min and max of each bucket. The min and max parameters will mysteriously adjust themselves keeping equal number of observation in each bucket.






                        share|improve this answer























                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          I use this trick for equal data bucketing. Suppose you have data in A1:A100 range. Put this formula in B1:



                          =MAX(ROUNDUP(PERCENTRANK($A$1:$A$100,A1) *4,0),1)


                          Fill down the formula all across B column and you are done. The formula divides the range into 4 equal buckets and it returns the bucket number which the cell A1 falls into. The first bucket contains the lowest 25% of values.



                          Adjust the number of buckets according to thy wish:



                          =MAX(ROUNDUP(PERCENTRANK([Range],[OneCellOfTheRange]) *[NumberOfBuckets],0),1)


                          The Advantage

                          The advantage of this solution is that you do not have to worry about the min and max of each bucket. The min and max parameters will mysteriously adjust themselves keeping equal number of observation in each bucket.






                          share|improve this answer












                          I use this trick for equal data bucketing. Suppose you have data in A1:A100 range. Put this formula in B1:



                          =MAX(ROUNDUP(PERCENTRANK($A$1:$A$100,A1) *4,0),1)


                          Fill down the formula all across B column and you are done. The formula divides the range into 4 equal buckets and it returns the bucket number which the cell A1 falls into. The first bucket contains the lowest 25% of values.



                          Adjust the number of buckets according to thy wish:



                          =MAX(ROUNDUP(PERCENTRANK([Range],[OneCellOfTheRange]) *[NumberOfBuckets],0),1)


                          The Advantage

                          The advantage of this solution is that you do not have to worry about the min and max of each bucket. The min and max parameters will mysteriously adjust themselves keeping equal number of observation in each bucket.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 28 at 10:47









                          Przemyslaw Remin

                          7117




                          7117






























                              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%2f489824%2fexcel-find-bucket-without-nested-ifs%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

                              flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                              Mangá

                              Eduardo VII do Reino Unido