How to Use the COUNT Function using Query function
The COUNT function in Google Sheets is used to count the number of numeric values in a specified range. You can use the COUNT function along with the QUERY function to filter and count the values based on certain conditions.
Here's how to use the COUNT function using the Query function in Google Sheets:
- Open your Google Sheet.
- Identify the data range that you want to query and count.
Example
Assume we have the following dataset in a Google Sheet:
A | B | C |
---|---|---|
Name | City | Age |
Alice | New York | 25 |
Bob | New York | 30 |
Carol | Los Angeles | 28 |
David | New York | 35 |
Eve | Los Angeles | 24 |
Let's say you want to count the number of people living in New York. You would use the QUERY and COUNT functions as follows:
- In an empty cell, type the following formula:
=QUERY(A1:C6, "SELECT COUNT(C) WHERE B = 'New York'")
- Press the 'Enter' key.
In this formula, A1:C6
is the range of data, and the query string SELECT COUNT(C) WHERE B = 'New York'
is used to count the number of values in column C (Age) where the value in column B (City) is "New York".
After executing the formula, the result will be displayed in the cell:
3
This indicates that there are 3 people living in New York in the given dataset.