COUNTBLANK (Array) COUNTBLANK (Array)

Array

The array whose element should be counted.

Returns

Number Number

The number of elements of the given array which are either blank or are equal to the empty text string.

Returns the number of elements of the given array which are either blank or are equal to the empty text string. COUNTBLANK ({ 10, BLANK (), "" }) COUNTBLANK ({ 10; BLANK (); "" }) returns 2, because BLANK () BLANK () and the empty text string "" are considered blank.

Unlike the COUNT and COUNTA functions, this function accepts a single parameter, which must be an array.

Count anything

Using a combination of FILTER and SIZE, you can use any criteria you like. Consider this formula:

FILTER (NumberArray, Element > 4)
FILTER (NumberArray; Element > 4)

The formula above returns a version of NumberArray where only elements greater than 4 are included. Use the SIZE function to count the number of elements in the returned array:

SIZE ( FILTER (NumberArray, Element > 4))
SIZE ( FILTER (NumberArray; Element > 4))

The formula above returns the number of elements of NumberArray which are greater than 4.

It's easy to replicate what COUNTBLANK does armed with this knowledge, and the fact that ISBLANK can be used to determine if an array element is blank:

SIZE ( FILTER (TextArray, ISBLANK (Element) || Element = ""))
SIZE ( FILTER (TextArray; ISBLANK (Element) || Element = ""))

The formula above returns the number of array elements which are blank or are equal to the empty text string, which is exactly what COUNTBLANK does. This formula uses the || "logical or" operator, which is equivalent to the OR function in non-array contexts.

Counting can also be done with REDUCE. Here's the equivalent REDUCE formula:

REDUCE (TextArray, (A, V) -> IF ( ISBLANK (V) || V = "", A + 1, A), 0)
REDUCE (TextArray; (A; V) -> IF ( ISBLANK (V) || V = ""; A + 1; A); 0)

Refer to the REDUCE documentation to learn more about how this example works (specifically, this example is similar to the XOR example in that documentation).

Example

COUNTBLANK ({ 10, BLANK (), "" })
COUNTBLANK ({ 10; BLANK (); "" })

Returns 2, because BLANK () BLANK () and the empty text string "" are considered blank.

fxEngine Shell Want this in your own terminal? A standalone version is coming. Get notified.
Loading fxEngine Shell