
Google Sheets’s QUERY function and Excel’s Power are among the most useful and powerful tools for advanced data analysis. Both have strong key functionalities to manipulate and analyze data. Despite their differences in interface and integration, their usefulness makes them important tools for data analysis. This article will show practical examples of data analysis while comparing both tools.
What is the QUERY Function?
The QUERY function in Google Sheets allows you to use SQL-like queries to filter, sort, group, merge, and aggregate data by using aggregate functions (SUM, COUNT, AVG, etc). The QUERY function also helps to create reports to analyze data while merging data from multiple sheets. Its single formula can handle multiple criteria which makes it easy to use. The most used clauses for data analysis in the QUERY function are:
- SELECT
- WHERE
- GROUP BY
- PIVOT
- ORDER BY
- LIMIT
- OFFSET
- LABEL
- FORMAT
- OPTIONS
N.B: While using clauses you must need to maintain the sequence.
Syntax:
=QUERY(data, query, [headers])
- data: The range of cells to perform the query on.
- query: The query to perform, written in Google Visualisation API Query Language. The SQL-like query you want to apply to the data.
- Headers [Optional]: It indicates the number of header rows at the top of the data. If omitted or set to -1, the value is guessed based on the content of the data.
What is a Power Query in Excel?
Power Query in Excel offers data import from various sources and allows users to connect various data sources. It offers key features like data cleaning, filtering, sorting, aggregation grouping, and combining multiple data sources. Power Query is an ideal choice for those working with complex datasets in Excel.
Sample Dataset:
Consider sample sales data to perform advanced data analysis. You can perform data analysis by creating different scenarios.
| Transaction ID | Date | Product | Category | Quantity | Price |
| 1 | 01/01/2024 | Laptop | Electronics | 2 | $1,200.00 |
| 2 | 03/01/2024 | Smartphone | Electronics | 3 | $800.00 |
| 3 | 05/01/2024 | TV | Electronics | 1 | $1,500.00 |
| 4 | 07/01/2024 | Headphones | Electronics | 2 | $100.00 |
| 5 | 10/01/2024 | Book | Books | 5 | $20.00 |
| 6 | 15/01/2024 | Chair | Furniture | 1 | $200.00 |
| 7 | 20/01/2024 | Table | Furniture | 2 | $300.00 |
| 8 | 25/01/2024 | Jacket | Clothing | 1 | $80.00 |
| 9 | 30/01/2024 | Shoes | Clothing | 2 | $120.00 |
| 10 | 02/02/2024 | Laptop | Electronics | 2 | $1,200.00 |
| 11 | 03/02/2024 | Smartphone | Electronics | 3 | $800.00 |
| 12 | 04/02/2024 | TV | Electronics | 1 | $1,500.00 |
| 13 | 05/02/2024 | Headphones | Electronics | 2 | $100.00 |
| 14 | 06/02/2024 | Chair | Furniture | 1 | $200.00 |
| 15 | 07/02/2024 | Table | Furniture | 2 | $300.00 |
| 16 | 08/02/2024 | Jacket | Clothing | 1 | $80.00 |
| 17 | 09/02/2024 | Shoes | Clothing | 2 | $120.00 |
Example: Filter and Sort Data to Perform Data Analysis
QUERY Function: To filter and sort data you can use the WHERE clause for multiple conditions. To use the sort functionality just use the ORDER BY clause. It will extract the only required data from the dataset along with the sequence.
Let’s use the following formula to filter and sort data based on different conditions. Select any cell and place the following formula.
Formula:
=QUERY(A1:F18, “SELECT * WHERE D = ‘Electronics’ ORDER BY E DESC”, 1)
This query filters the data to show only the “Electronics” category and then sorts these results by the quantity sold in descending order. It will display the highest quantities first.
Output:
| Transaction ID | Date | Product | Category | Quantity | Price |
| 2 | 03/01/2024 | Smartphone | Electronics | 3 | $800.00 |
| 11 | 03/02/2024 | Smartphone | Electronics | 3 | $800.00 |
| 1 | 01/01/2024 | Laptop | Electronics | 2 | $1,200.00 |
| 4 | 07/01/2024 | Headphones | Electronics | 2 | $100.00 |
| 10 | 02/02/2024 | Laptop | Electronics | 2 | $1,200.00 |
| 13 | 05/02/2024 | Headphones | Electronics | 2 | $100.00 |
| 3 | 05/01/2024 | TV | Electronics | 1 | $1,500.00 |
| 12 | 04/02/2024 | TV | Electronics | 1 | $1,500.00 |
Excel Power Query: To sort and filter the data load your data in the power query editor,
- Click on the drop-down arrow in the Category column header.
- In the filter menu, deselect all categories except “Electronics”.
- Click OK to apply the filter. This filters the data to show only rows where the category is “Electronics.”
Sort the Data:
- Click on the drop-down arrow in the Quantity column header.
- Select Sort Descending to sort the filtered data by the quantity in descending order. This will place the highest quantities at the top.

Image by Author
Example: Data Aggregation: SUM and Group Data By Category
QUERY Function: You can aggregate data by using SQL-like syntax, it allows you to perform SUM, COUNT, AVG, etc. within a GROUP BY clause in a single formula. While using the GROUP BY clause for calculation, you can use the LABEL clause to provide customized and descriptive names of the aggregated data. You can handle complex data analysis by using those features to group and summarize your data.
Let’s use the following formula to get the total quantity for each category and label it as ‘Total Quantity’. You can select any cell to place the following formula.
Formula:
=QUERY(A1:F18, “SELECT D, SUM(E) GROUP BY D LABEL SUM(E) ‘Total Quantity'”, 1)
This QUERY formula will group your data by category and calculate the total quantity for each category then it will label the sum as “Total Quantity” in the output.
Output:
| Category | Total Quantity |
| Books | 5 |
| Clothing | 6 |
| Electronics | 16 |
| Furniture | 6 |
Excel Power Query: Load the data in the Power Query Editor,
- Select the Category column (D) >> Click on the Group By button from the Transform tab.
- In the Group By dialog box: Set the Group by field to Category.
- Under the New column name, type: ‘Total Quantity’.
- Select Operation to Sum.
- Select the Column to Quantity (which corresponds to column E in your dataset).
- Click OK to apply the grouping.

Image by Author
Output:

Image by Author
Comparison of Google Sheet’s QUERY function and Excel’s Power Query:
Listed the common data analysis tasks that both tools can perform. To use the QUERY function you will need to write formulas whereas Power Query auto-creates the formula based on the commands.
| Data Analysis | Google Sheet’s QUERY Function | Power Query in Excel |
| Filter and Sort Data | SQL queries like WHERE and ORDER BY clauses are used to filter and sort data based on conditions. | It has built-in features to Filter and Sort data based on custom criteria. |
| Aggregate Data | It aggregates data with aggregation functions like SUM, COUNT, AVG, MIN, MAX, etc. with a GROUP BY clause to summarize data. | It has built-in tools and features to aggregate data for grouping and summarizing. |
| Merge Data | Manually merges data from different spreadsheets using LOOKUP and IMPORTRANGE functions within the QUERY function. | It can merge data from different sources seamlessly. |
| Data Connection | By default works within Google Sheets. To create an external connection IMPROTRANGE function can be used. | It connects to a wide variety of data sources, including databases, CSV files, Text files, Excel files, web services, etc. |
| Dataset Type | It can easily handle small to moderately large datasets within Google Sheets. It can handle large datasets but performance can degrade with larger formulas. | It is optimized for larger and more complex datasets. Built-in features offer various options for data analysis. |
| Learning Curve | It requires prior knowledge of SQL for complex queries. Otherwise easy to use like any formula. | Its interface is quite similar to Excel’s features and commands. All types of users can use it with basic knowledge. |
Conclusion
QUERY function is an effective and powerful tool to perform data analysis in Google Sheets Excel offers other tools and options for data analysis along with the Power Query tool. QUERY function helps to cover most of the functionalities of Excel’s Power Query by using different clauses. Based on your dataset and type of analysis you can choose which one to use. In the comparison table, shared their similarities and differences. Whether you’re filtering, aggregating, transforming, or combining data, both tools offer powerful solutions that can be adapted to your specific needs.
