2

I have a column XXX like this :

XXX


A
Aruin
Avolyn
B
Batracia
Buna
...

I would like to count a cell only if the string in the cell has a length > 1. How to do that? I'm trying :

COUNTIF(XXX1:XXX30, LEN(...) > 1)

But what should I write instead of ... ?

Thank you in advance.

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
user2768549
  • 23
  • 1
  • 3

5 Answers5

5

For ranges that contain strings, I have used a formula like below, which counts any value that starts with one character (the ?) followed by 0 or more characters (the *). I haven't tested on ranges that contain numbers.

=COUNTIF(range,"=?*")

xolotl
  • 51
  • 1
  • 3
5

To do this in one cell, without needing to create a separate column or use arrayformula{}, you can use sumproduct.

=SUMPRODUCT(LEN(XXX1:XXX30)>1)

If you have an array of True/False values then you can use -- to force them to be converted to numeric values like this:

=SUMPRODUCT(--(LEN(XXX1:XXX30)>1))

Credit to @greg who posted this in the comments - I think it is arguably the best answer and should be displayed as such. Sumproduct is a powerful function that can often to be used to get around shortcomings in countif type formulae.

Cassiopeia
  • 313
  • 1
  • 4
  • 16
2

Create another list using an =ARRAYFORMULA(len(XXX1:XXX30)>1) and then do a COUNTIF based on that new list: =countif(XXY1:XXY30,true()).

mdega
  • 106
  • 6
  • 2
    To offer an alternative to a helper list, try `=SUMPRODUCT(--(LEN(XXX1:XXX30)>1))`. – Greg Dec 21 '15 at 17:43
0

A simple formula that works for my needs is =ROWS(FILTER(range,LEN(range)>X))

The Google Sheets criteria syntax seems inconsistent, because the expression that works fine with FILTER() gives an erroneous zero result with COUNTIF().

Here's a demo worksheet

0

Another approach is to use the QUERY function.

This way you can write a simple SQL like statement to achieve this.

For example:

=QUERY(XXX1:XXX30,"SELECT COUNT(X) WHERE X MATCHES '.{1,}'")

To explain the MATCHES criteria: It is a regex that matches every cell that contains 1 or more characters.

The . operator matches any character.

The {1,} qualifies that you only want to match cells that have at 1 or more characters in them.

Here is a link to another SO question that describes this method.

Sean
  • 963
  • 1
  • 10
  • 28