Sorting rows in a Google Sheets pivot table usually defaults to the first column, but what if you need to sort by the second column instead?
Whether you’re organizing sales data by totals or ranking tasks by priority, sorting pivot table rows by the second column can make your data more meaningful and easier to analyze.
In this tutorial, I’ll show you step-by-step how to sort pivot table rows by the second column in Google Sheets.
This tutorial is included in our complete guide on How to Sort and Filter Pivot Tables in Google Sheets, where you’ll find step-by-step methods for sorting, filtering, and ranking Pivot Table data efficiently.
Introduction
Google Sheets doesn’t offer a built-in option in the pivot table editor to sort rows by any column other than the first. To work around this limitation, we’ll use a helper column.
Let’s say your pivot table (not the source data) includes this structure: Item, P.O. Date, and SUM of Order Qty.
- The first two fields — Item and P.O. Date — are placed under Rows.
- The last field — SUM of Order Qty — is placed under Values.
Now, suppose you want to sort the pivot table rows by P.O. Date. Since it’s the second row field, the default sorting behavior won’t produce the expected order.
Why?
Google Sheets lets you sort each row group by the field itself or by its corresponding Values field (e.g., SUM of Order Qty). However, sorting of the first row field always takes precedence and overrides the sorting of the second field.
So even if you try to sort by P.O. Date, the grouping and sort order of Item will dominate, making it hard to achieve the intended result.
To fix this, I’ll show you how to sort pivot table rows by the second column — like P.O. Date — using a helper column.
Sorting Pivot Table Rows by Another Column in Google Sheets
Let’s walk through the steps using a mock dataset:
| Item | Supplier | P.O. Number | P.O. Date | Unit | Order Qty |
|---|---|---|---|---|---|
| Gravel 20 mm | Vendor 1 | 1500 | 01/01/2022 | M³ | 315 |
| Gravel 40 mm | Vendor 2 | 1501 | 01/01/2022 | M³ | 180 |
| Gravel 40 mm | Vendor 2 | 1502 | 01/01/2022 | M³ | 450 |
| Roadbase | Vendor 3 | 1503 | 02/01/2022 | M³ | 225 |
| Roadbase | Vendor 6 | 1506 | 03/01/2022 | M³ | 225 |
| Gravel 5-10 mm | Vendor 4 | 1504 | 03/01/2022 | M³ | 45 |
| Gravel 10-20 mm | Vendor 5 | 1505 | 03/01/2022 | M³ | 90 |
You can copy this data into cell range A1:F8 of your Sheet.
We want to group this purchase order data by Item → P.O. Date and show the sum of Order Qty.
Pivot Table Settings
- Drag the Item and P.O. Date into the Rows section.
- Drag Order Qty into the Values section.
This setup will create a pivot table, but the P.O. Date entries won’t be sorted as intended, because sorting defaults to the first column in the row grouping.

To sort pivot table rows by the second column (e.g., P.O. Date), we’ll use a helper column.
Using a Helper Column to Sort Pivot Table Rows by Second Column
We’ll use column G as a helper column (which is currently empty).
In cell G1, enter the following array formula:
=ArrayFormula(
VSTACK(
"Helper",
IFNA(
XMATCH(
A2:A,
CHOOSECOLS(
SORT(
SORTN(
SORT(HSTACK(A2:A, D2:D), 2, TRUE),
9^9, 2, 1, TRUE
),
2, TRUE, 1, 1
),
1
)
)
)
)
)
- Replace
A2:Awith the first grouping column (placed first under Rows in the Pivot Table editor). - Replace
D2:Dwith the column you want to sort by (e.g., P.O. Date, the second row grouping in the pivot table).

How the Formula Works (Brief Explanation)
This formula generates a helper column that assigns a sort order to the first row group based on the second column (e.g., P.O. Date):
- HSTACK combines the first and second ‘Rows’ fields.
- SORT and SORTN organize the values based on the second column and return unique rows.
- CHOOSECOLS selects only the first column from the sorted output.
- XMATCH matches each original value to the sorted list and returns the corresponding order.
- VSTACK adds the header row Helper to make the array usable in the pivot table.
Update the Pivot Table
Now, open the Pivot Table editor and do the following:
- Update the data range from
A1:F8toA1:G8. - Add the Helper column to the top of the Rows section.

Optionally, hide the Helper column in the pivot table to keep the display clean.
With this setup, the pivot table will now be sorted by the second column (e.g., P.O. Date) instead of the default first column.
Sorting Pivot Table Rows in Descending Order
If you’d like to sort the pivot table rows by the second column in descending order:
- In the Pivot Table editor, select Descending as the sort order for the Helper field.
- Also, set P.O. Date to sort in Descending order to reflect the reverse chronological order within each group.
In case the PO dates of the same item of different vendors are different, doing so the Item can not be grouped anymore, right?
Hi, Jimmy,
In that case, place the field Helper between Item and Supplier, and hide it.