Forum Discussion

mehoop's avatar
mehoop
Copper Contributor
Dec 12, 2020

Formula not working for me

I am trying to get my spreadsheet to count how many zip codes that I have that are ">=" to a certain cell but "<=" another cell with the following formula and it is not working.

 

=COUNTIFS(G2:G302,">="&H2,G2:G302,"<"&I2)

9 Replies

  • SergeiBaklan's avatar
    SergeiBaklan
    Diamond Contributor

    mehoop 

    It's still desirably to know how your zip codes looks like. Let assume they are all texts which represent numbers like in this sample

    COUNTIFS() automatically transforms texts which looks like numbers into numbers. Thus in our sample in comparison text "192000" will be in background converted into the number 192000. There is the know trick to avoid that, to add CHAR(174) to such text

    =COUNTIFS(F2:F6,">="&F9&CHAR(174),F2:F6,"<="&F10&CHAR(174))

    or to work with SUMPRODUCT() which works as expected without surprises

    =SUMPRODUCT((F2:F6>=F9)*(F2:F6<=F10))

     

  • mehoop 

    The following

    = LET(
      numeric,  VALUE(SUBSTITUTE(zip, "-", "")),
      filteredZIP, FILTER(zip, (numeric > startN) * (numeric <= endN) ),
      COUNTA(filteredZIP) )

    would convert hyphenated zips to numbers and use the numeric values as a filter prior to counting.

  • sankalp_parmar's avatar
    sankalp_parmar
    Copper Contributor

    mehoop As you are using comparison operators ">=", both the zip code and fixed values cells I2 and H2 should be numbers. If zicode is like 600-2000, Excel will treat it as text and can't validate the 'greater than or less than' equal conditions 

      • sankalp_parmar's avatar
        sankalp_parmar
        Copper Contributor

        SergeiBaklan Because both are treated as text value. Although if you put "600-2000">"600-1999" , it returns true, it does not mean that 1st one is actually greater than 2nd. Lets take "A" and "B" and put formula in a cell as ="B">"A" . This will give True because in alphabets B comes after A. In simiar manner "600-2000">"600-1999". Its more of sorting

  • SergeiBaklan's avatar
    SergeiBaklan
    Diamond Contributor

    mehoop 

    In theory it shall work if you mean AND condition and depends on if all are texts, or all are numbers or mix.

Resources