Comparison of strings containing inequalities in excel countif() function











up vote
1
down vote

favorite
1












I'm analyzing some survey data in which the responses are in the form of a string containing inequalities, e.g.



a) < 5



b) 5-10



c) 11-15



d) > 15



I'm attempting to tabulate responses using the Countifs function, and Excel does not appear to parse the value of the cell with the criteria argument as a string, and so returns 'False' for those bins; it does not evaluate a cell containing the string '< 5' as being equal to another cell containing '< 5', or the literal argument "< 5".



A comparison of the reference cells in other formulas, using = or EXACT() returns TRUE. (screenshot to show an example)



I know the criteria argument of the conditional operators like COUNTIF(), SUMIF(), etc. use strings with inequalities when they're actually serving as operators, but I can't figure out how to suppress this and evaluate these cells as simple strings. Thanks so much!










share|improve this question
























  • Does anything here help? superuser.com/questions/1132899/…
    – Rey Juna
    Dec 7 at 22:52










  • Better share some sample data with us to create proper solution!!
    – Rajesh S
    Dec 8 at 5:37















up vote
1
down vote

favorite
1












I'm analyzing some survey data in which the responses are in the form of a string containing inequalities, e.g.



a) < 5



b) 5-10



c) 11-15



d) > 15



I'm attempting to tabulate responses using the Countifs function, and Excel does not appear to parse the value of the cell with the criteria argument as a string, and so returns 'False' for those bins; it does not evaluate a cell containing the string '< 5' as being equal to another cell containing '< 5', or the literal argument "< 5".



A comparison of the reference cells in other formulas, using = or EXACT() returns TRUE. (screenshot to show an example)



I know the criteria argument of the conditional operators like COUNTIF(), SUMIF(), etc. use strings with inequalities when they're actually serving as operators, but I can't figure out how to suppress this and evaluate these cells as simple strings. Thanks so much!










share|improve this question
























  • Does anything here help? superuser.com/questions/1132899/…
    – Rey Juna
    Dec 7 at 22:52










  • Better share some sample data with us to create proper solution!!
    – Rajesh S
    Dec 8 at 5:37













up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






1





I'm analyzing some survey data in which the responses are in the form of a string containing inequalities, e.g.



a) < 5



b) 5-10



c) 11-15



d) > 15



I'm attempting to tabulate responses using the Countifs function, and Excel does not appear to parse the value of the cell with the criteria argument as a string, and so returns 'False' for those bins; it does not evaluate a cell containing the string '< 5' as being equal to another cell containing '< 5', or the literal argument "< 5".



A comparison of the reference cells in other formulas, using = or EXACT() returns TRUE. (screenshot to show an example)



I know the criteria argument of the conditional operators like COUNTIF(), SUMIF(), etc. use strings with inequalities when they're actually serving as operators, but I can't figure out how to suppress this and evaluate these cells as simple strings. Thanks so much!










share|improve this question















I'm analyzing some survey data in which the responses are in the form of a string containing inequalities, e.g.



a) < 5



b) 5-10



c) 11-15



d) > 15



I'm attempting to tabulate responses using the Countifs function, and Excel does not appear to parse the value of the cell with the criteria argument as a string, and so returns 'False' for those bins; it does not evaluate a cell containing the string '< 5' as being equal to another cell containing '< 5', or the literal argument "< 5".



A comparison of the reference cells in other formulas, using = or EXACT() returns TRUE. (screenshot to show an example)



I know the criteria argument of the conditional operators like COUNTIF(), SUMIF(), etc. use strings with inequalities when they're actually serving as operators, but I can't figure out how to suppress this and evaluate these cells as simple strings. Thanks so much!







microsoft-excel worksheet-function






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 7 at 23:27









Twisty Impersonator

17.6k136395




17.6k136395










asked Dec 7 at 22:17









William Richter

82




82












  • Does anything here help? superuser.com/questions/1132899/…
    – Rey Juna
    Dec 7 at 22:52










  • Better share some sample data with us to create proper solution!!
    – Rajesh S
    Dec 8 at 5:37


















  • Does anything here help? superuser.com/questions/1132899/…
    – Rey Juna
    Dec 7 at 22:52










  • Better share some sample data with us to create proper solution!!
    – Rajesh S
    Dec 8 at 5:37
















Does anything here help? superuser.com/questions/1132899/…
– Rey Juna
Dec 7 at 22:52




Does anything here help? superuser.com/questions/1132899/…
– Rey Juna
Dec 7 at 22:52












Better share some sample data with us to create proper solution!!
– Rajesh S
Dec 8 at 5:37




Better share some sample data with us to create proper solution!!
– Rajesh S
Dec 8 at 5:37










2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted










As stated The countifs in the criteria accepts string and thus <5 is reading less than five not the string.



To get it to look at the string use "="



=COUNTIF(C2,"="&C3)


By adding the = before the <, Excel sees it as a string and not an operand.



enter image description here






share|improve this answer




























    up vote
    0
    down vote













    Instead of fighting the bugs of Excel and getting it to recognize the < symbol, I'd solve the problem by removing it altogether. Just replace <5 with something like 5_or_less and then COUNTIF should work.



    =SUBSTITUTE(A1,"<5","5_or_less") will do the replacement for A1 and <5. You can put this in a new column, say B1. Then do another replacement for >15 in C1 like =SUBSTITUTE(B1,">15","15_or_more"). Then runCOUNTIFon columnC`.






    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',
      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%2f1381776%2fcomparison-of-strings-containing-inequalities-in-excel-countif-function%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      1
      down vote



      accepted










      As stated The countifs in the criteria accepts string and thus <5 is reading less than five not the string.



      To get it to look at the string use "="



      =COUNTIF(C2,"="&C3)


      By adding the = before the <, Excel sees it as a string and not an operand.



      enter image description here






      share|improve this answer

























        up vote
        1
        down vote



        accepted










        As stated The countifs in the criteria accepts string and thus <5 is reading less than five not the string.



        To get it to look at the string use "="



        =COUNTIF(C2,"="&C3)


        By adding the = before the <, Excel sees it as a string and not an operand.



        enter image description here






        share|improve this answer























          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          As stated The countifs in the criteria accepts string and thus <5 is reading less than five not the string.



          To get it to look at the string use "="



          =COUNTIF(C2,"="&C3)


          By adding the = before the <, Excel sees it as a string and not an operand.



          enter image description here






          share|improve this answer












          As stated The countifs in the criteria accepts string and thus <5 is reading less than five not the string.



          To get it to look at the string use "="



          =COUNTIF(C2,"="&C3)


          By adding the = before the <, Excel sees it as a string and not an operand.



          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 8 at 0:21









          Scott Craner

          10.9k1814




          10.9k1814
























              up vote
              0
              down vote













              Instead of fighting the bugs of Excel and getting it to recognize the < symbol, I'd solve the problem by removing it altogether. Just replace <5 with something like 5_or_less and then COUNTIF should work.



              =SUBSTITUTE(A1,"<5","5_or_less") will do the replacement for A1 and <5. You can put this in a new column, say B1. Then do another replacement for >15 in C1 like =SUBSTITUTE(B1,">15","15_or_more"). Then runCOUNTIFon columnC`.






              share|improve this answer

























                up vote
                0
                down vote













                Instead of fighting the bugs of Excel and getting it to recognize the < symbol, I'd solve the problem by removing it altogether. Just replace <5 with something like 5_or_less and then COUNTIF should work.



                =SUBSTITUTE(A1,"<5","5_or_less") will do the replacement for A1 and <5. You can put this in a new column, say B1. Then do another replacement for >15 in C1 like =SUBSTITUTE(B1,">15","15_or_more"). Then runCOUNTIFon columnC`.






                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  Instead of fighting the bugs of Excel and getting it to recognize the < symbol, I'd solve the problem by removing it altogether. Just replace <5 with something like 5_or_less and then COUNTIF should work.



                  =SUBSTITUTE(A1,"<5","5_or_less") will do the replacement for A1 and <5. You can put this in a new column, say B1. Then do another replacement for >15 in C1 like =SUBSTITUTE(B1,">15","15_or_more"). Then runCOUNTIFon columnC`.






                  share|improve this answer












                  Instead of fighting the bugs of Excel and getting it to recognize the < symbol, I'd solve the problem by removing it altogether. Just replace <5 with something like 5_or_less and then COUNTIF should work.



                  =SUBSTITUTE(A1,"<5","5_or_less") will do the replacement for A1 and <5. You can put this in a new column, say B1. Then do another replacement for >15 in C1 like =SUBSTITUTE(B1,">15","15_or_more"). Then runCOUNTIFon columnC`.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 7 at 23:59









                  Docconat

                  83




                  83






























                      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%2f1381776%2fcomparison-of-strings-containing-inequalities-in-excel-countif-function%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