QUERY
The QUERY
function in Google Sheets is a powerful tool to run a Google Visualization API Query Language query across data. Whether you're filtering and sorting data, calculating aggregates, or creating custom reports, the QUERY
function simplifies the task. Dive into our comprehensive guide to master its application.
Function Syntax and Parameters
Syntax: QUERY(data, query, [headers])
Parameters:
data
: The range of cells or an array containing the data to be queried.query
: The query in the Google Visualization API Query Language.[headers]
: [Optional] The number of header rows to include.
Step-by-Step Tutorial
-
Basic QUERY formula:
- Example:
=QUERY(A1:E10, "SELECT A, B, D WHERE C > 100")
- Result: Returns columns A, B, and D from range A1:E10 if the value in column C is greater than 100.
- Example:
-
Using headers:
- Example: If the range A1:E10 has headers,
=QUERY(A1:E10, "SELECT A, B, D WHERE C > 100", 1)
will include the header row in the result.
- Example: If the range A1:E10 has headers,
Use Cases and Scenarios
- Data Filtering: Extract specific rows based on specified conditions.
- Data Sorting: Sort data based on certain columns.
- Aggregation: Calculate and summarize data using functions like COUNT, SUM, AVERAGE, etc.
Related Functions
VLOOKUP
: Look up and retrieve data from a specific column in a range.SUMIF
: Add up values from a range that meet specified criteria.