*30*

You can use the following syntax to create a pivot table using Google Sheets Query:

=query(A1:C13, "select A, sum(C) group by A pivot B")

In this example, we choose column **A** to represent the rows of the pivot table, column **B** to represent the columns of the pivot table, and the values in column **C** to be displayed inside the pivot table.

The following examples show how to use this syntax in practice.

**Example 1: Create a Pivot Table Using SUM()**

We can use the following formula to create a pivot table that displays the total sales by product and by region for a certain company:

We would interpret the values in the pivot table as follows:

- The total sales of product A in the East region was
**388**. - The total sales of product B in the East region was
**0**. - The total sales of product C in the East region was
**476**. - The total sales of product D in the East region was
**0**.

And so on.

**Example 2: Create a Pivot Table Using AVG()**

We can use the following formula to create a pivot table that displays the average sales by product and by region for a certain company:

We would interpret the values in the pivot table as follows:

- The average sales of product A in the East region was
**388**. - The average sales of product B in the East region was
**0**. - The average sales of product C in the East region was
**238**. - The average sales of product D in the East region was
**0**.

And so on.

**Additional Resources**

Google Sheets Query: How to Select Multiple Columns

Google Sheets Query: How to Use Group By

Google Sheets Query: How to Use Order By