Google-sheets – Why is Google Sheets counting this cell as both blank and not blank

formulasgoogle sheets

Google Sheets appears to be counting my blank cell as both blank and non-blank.

The cell in question, A1, is filled with this formula: =IF(1=0,"Some output",""). The output, of course, is an empty string, since 1 does not equal 0.

Using countif, I'm running into the problem that it is counting that cell when I use both the comparison "<>" and "". So a cell with =COUNTIF(A1, "<>") returns 1, and a cell with =COUNTIF(A1, "") also returns 1.

In Excel or LibreOffice Calc, the values of the two countif functions line up with my expectations, depending on if the cell A1 has a resulting value or not. But Google Sheets can't make up its mind on if the cell is blank or not and ends up counting it both times. (It doesn't count it for both if there is a value returned, nor does it count it both times if A1 is truly empty with no formula.)

Is there something wrong with my formulas? Or is this a bug in Google Sheets? I'd like to be able to correctly count or ignore blank cells in another formula.

Best Answer

Try one of these instead:

=COUNTIF(A1,"<>"&CHAR(0))

or

=COUNTIF(A1,"<>"&NULL)

Either will return the expected result of 0 if the formula =IF(1=0,"Some output","") resides in A1.