This tutorial will explain various ways of COUNTIF function in LibreOffice Calc can be used to count strings, numbers from a cell, range, rows, columns etc.
Table of Contents
COUNTIF Function – Syntax
COUNTIFS(Range1; Criterion1 [; Range2; Criterion2 [; ...]])
Returns the count of rows or columns that meet the criteria.
With Number in Formula
The below example returns the count of 20 in the range A1:A7. In this below example, number 20 is present twice in the range. Thus the result is 2.
With Number as Cell Reference
You can also specify 20 as a cell reference. The result would be similar. COUNTIF would try to count the value specified in cell D1.
Count Numbers with Operators
COUNTIF also can count using logical operators. It can count the number of rows and columns which satisfy the greater than and less than conditions.
In the above example, if we need to count the number of rows with values greater than 20, use the formula below. Note that the greater than operator should be used as a string (i.e., double quotes).
Without cell reference, you can use
COUNTIF(A1:A7,">20") as well, which would give the same result.
< sign to find out the number of rows less than the specified value.
Not Equal To
Similarly, use the
<> sign to find out the number of rows not equal to the specified value.
Equal, Greater Than Equal, Less Than Equal
You can use
<= in the above formulas to get the results for Equal, Greater Than Equal and Less Than Equal to a specified value.
COUNTIF Using OR
You can also combine two COUNTIF functions to achieve more. The below example returns the count of rows which is 20 or 10.
Using another function inside COUNTIF
It is possible to use another Calc function in the criteria of COUNTIF. The following example returns the values greater than the average of A1:A7, i.e. 32.7
Count String or Text
COUNTIF can be used to count any text, or string as well in Calc cells like the numbers. The formula is exactly the same. Only the criteria should be a text/string specified by double quotes.
Count a specific text
The following example counts the text “apple” in the range A1:A10.
Count all text
The above example, A1:A10, has a mix of values – numbers and texts. If you want to count the rows with texts only, the formula below can be used.
* gives the count of all the cells, including numeric and text. The COUNT() function gives the count of only numeric cells.
- Use the criteria below to count all the cells with text starting with any text (e.g. “apple”).
- Use the criteria below to count all the cells with text containing any matching string (e.g. “apple”).
- To count the cells with matching string with any one character at the end, use the below criteria.
So, this is how you can use COUNTIF for various uses in LibreOffice Calc.
Do let me know in the comment box if you have any questions.