Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

COUNTIF can't count non-blank formula results?

I am looking for a criterion to use in =countif(range_of_formulas, [criterion]) that will identify non-blank results of formulas. I've found quite a few of those, like "<>" , "<>"&"" , "<>""" , ">""" , "*" and more (e.g. on SO here and here). But each criterion seems to work only in some situations and not others, and they all fail in the following situation:

enter image description here columns A and B have my original data. Column D presents results of the formulas you see in column C. Column F shows results of countif using different criteria (as shown in column E) to count the non-blank results in column D. None of them arrive at the right count - 5.

In my research (and in answers to this question, before I edited to narrow it down) I've seen many workarounds that would get the right count. But what I am asking is if there is a criterion that would work in countif, or if countif cannot reliably count non blank formula results?
(or maybe someone can say under which conditions it can or can't be used).

like image 216
eli-k Avatar asked Aug 13 '17 06:08

eli-k


People also ask

Does Countif work with blank cells?

While COUNTBLANK returns the number of blank cells, you can also use COUNTIF or COUNTIFS to achieve the same result. COUNTIF counts the number of cells that meet the criteria you define within the formula itself. Because you want to count empty cells, you can use a blank text string as your criteria.

Why is the Countif formula not working?

Common ProblemsThe COUNTIF function returns incorrect results when you use it to match strings longer than 255 characters. To match strings longer than 255 characters, use the CONCATENATE function or the concatenate operator &. For example, =COUNTIF(A2:A5,"long string"&"another long string").

Does the count function ignore blanks?

The COUNTA function does not count empty cells. If you do not need to count logical values, text, or error values (in other words, if you want to count only cells that contain numbers), use the COUNT function.


1 Answers

This can be achieved with a simple change on the first forumla to force the output to be a string value (Should you need to perform a calculation with the numerical results, multiply them by 1 to convert back to number when they are being used)

I have simply joined a blank string to the end of the result on the first formula and wrapped it in brackets to keep excel happy:

=(IF(AND(B1=1,ISBLANK(A1)=FALSE),A1,"")&"")

Now you can use the wildcards for any character (?) and any length of string (*) together as your criteria to achieve your desired total of 5:

=COUNTIF($D$1:$D$8,"?*")

enter image description here

like image 195
Glitch_Doctor Avatar answered Oct 19 '22 03:10

Glitch_Doctor