HomeGoogle DocsSpreadsheetHow to Sort Pivot Table Columns in Custom Order in Google Sheets

How to Sort Pivot Table Columns in Custom Order in Google Sheets

This tutorial explains how to sort Pivot Table columns in a custom order in Google Sheets. Since Google Sheets doesn’t provide a built-in option for custom column sorting, you’ll use a helper column to control the order of the Pivot Table field values.

If you’re not familiar with the built-in sorting options, first see How to Sort a Pivot Table by Value in Google Sheets.

With that covered, let’s look at the steps.

Sample Data and Setup

To sort Pivot Table columns in a custom order, we must first define the desired order using a helper column.

The helper column controls the custom sort order without appearing as a separate field in the final Pivot Table.

If you plan to insert the Pivot Table on the same sheet, I recommend leaving two empty rows above the sample data.

Assume you have the following data in the range A3:D10:

ProjectManagerStatusHours
AlphaSonaIn Progress18
BetaKaranCompleted12
GammaOliviaOn Hold9
DeltaKeerthiIn Progress15
EpsilonNehaCompleted20
ZetaSophiaOn Hold7
EtaAlexIn Progress11

Our goal is to display the Status columns in the order In Progress → On Hold → Completed. However, if you create a Pivot Table with Project in Rows, Status in Columns, and Hours in Values, Google Sheets displays the columns in the default order Completed → In Progress → On Hold.

Creating a Helper Column to Define the Custom Sort Order

To sort the Status column in a custom order, enter the following formula in cell E3, next to the sample data:

=ARRAYFORMULA(
 VSTACK("",
   IFNA(
     XMATCH(
       C4:C,
       VSTACK("In Progress", "On Hold", "Completed")
     )
   )
 )
)

The helper formula uses open-ended ranges, so it automatically includes new rows added to the source data.

Google Sheets sample data with a helper column defining a custom sort order for Pivot Table columns

The formula assigns the following sort positions:

  • In Progress1
  • On Hold2
  • Completed3

The header is intentionally left blank so that no helper column heading appears above the Pivot Table.

XMATCH matches each value in C4:C against the custom order defined in VSTACK("In Progress", "On Hold", "Completed") and returns its position (1, 2, or 3).

Note: Include all unique values from the Status column in the VSTACK array, in the exact order you want them to appear in the Pivot Table.

Create the Pivot Table

When creating the Pivot Table, include the helper column in the source data range.

Select A3:E10, then click Insert > Pivot table.

Choose Existing sheet, enter G1 as the location, and click Create.

In the Pivot Table editor:

  • Click Add next to Rows and add the Project field.
  • Click Add next to Columns and add the Status field.
  • Click Add next to Values and add the Hours field.

This creates the following Pivot Table with the default column order:

ProjectCompletedIn ProgressOn HoldGrand Total
Alpha1818
Beta1212
Delta1515
Epsilon2020
Eta1111
Gamma99
Zeta77
Grand Total32441692

Notice that the columns appear in the order Completed → In Progress → On Hold.

To display them in our custom order, follow these steps:

  • Click Add next to Columns and add Column E. Since the helper column has no header, it appears as Column E.
  • Drag Column E above the Status field in the Columns section.
    Google Sheets first groups the columns by the helper values (1, 2, and 3), then displays the corresponding Status labels in that order.
  • In the Status field settings, uncheck Show totals.
    Google Sheets Pivot Table editor showing the helper column placed above the Status column field
  • Hide row 2 by right-clicking the row number and selecting Hide row.

The Pivot Table columns will now appear in the order In Progress → On Hold → Completed.

Final Pivot Table with Columns in Custom Order

After hiding row 2, the Grand Total column heading is also hidden. To restore it, enter the following formula in cell L3 (the next empty cell to the right of the Pivot Table header row):

="Grand Total"&REPT(" ", 25)

Then:

  • Align the text to the right.
  • Change the font color to white.
  • Adjust the number in REPT if necessary to position the Grand Total label above the last column.
Restoring the Grand Total label in a Google Sheets Pivot Table after hiding the helper row

Note: If you later add another unique value to the Status column and include it in the VSTACK array, the Pivot Table will expand to the right. If the formula in L3 blocks the expansion, Google Sheets will return a #REF! error. In that case, move the formula to a cell farther to the right.

That’s how to sort Pivot Table columns in a custom order in Google Sheets.

Sample Sheet

Make a copy of the following Google Sheets file to explore the helper column formula and the Pivot Table used in this tutorial.

Copy the Sample Sheet

Frequently Asked Questions

Does Google Sheets have a built-in option to sort Pivot Table columns in a custom order?

No. Google Sheets doesn’t provide a built-in option for this. You’ll need to use a helper column as a workaround.

What about sorting Pivot Table rows in a custom order?

Sorting Pivot Table rows requires a different setup. The helper formula used to define the custom order is similar, but the Pivot Table configuration and the method used to restore the Grand Total label are different.

For the complete steps, see How to Sort Pivot Table Rows in Custom Order in Google Sheets.

Can I create the same result without a Pivot Table?

Yes. You can use the QUERY function instead. See Custom Order for QUERY Pivot Headers in Google Sheets.

For the sample data in this tutorial, you can use the following formula:

=ArrayFormula(
   LET(
      qry, QUERY(A3:D, "select A, sum(D) where A is not null group by A pivot C", 1), 
      order, HSTACK("*Project*", "*In Progress*", "On Hold", "Completed"), 
      CHOOSECOLS(qry, XMATCH(order, chooserows(qry, 1), 2))
   )
)

Conclusion

Google Sheets doesn’t include a built-in option to sort Pivot Table columns in a custom order, but a helper column provides a reliable workaround. Once configured, the custom column order updates automatically whenever the Pivot Table refreshes, provided new data is included in the Pivot Table’s source range. This makes the approach ideal for dashboards and recurring reports.

Prashanth K V
Prashanth K V
Your Trusted Google Sheets and Excel Expert Prashanth K V is a Diamond Product Expert in Google Sheets, officially recognized by Google for his contributions to the Docs Editors Help Community and featured in the Google Product Experts Directory. Explore his blog to learn advanced formulas, automation tips, and problem-solving techniques to elevate your spreadsheet skills.

Most Discussed

More like this

Google Sheets Document Expiry Tracker Template (Free Download)

Missing your visa renewal, vehicle insurance renewal, emission certificate expiry, domain renewal, or scheduled...

Google Sheets Habit Tracker Template (Free & Automated)

Want to monitor your habits and track your progress over a month or across...

How to Sort a Pivot Table by Value in Google Sheets

Google Sheets lets you sort Pivot Tables by row fields, column fields, or summarized...

2 COMMENTS

    • Hi, Chanelle Marcelo,

      In cell D3, insert the following formula.

      ={"Sort";ArrayFormula(ifna(REGEXEXTRACT(A4:A&"","[0-9]+")*1))}

      Make the following two changes within the pivot table editor panel.
      1. Modify the range to A3:D1000.
      2. Add the new column under Add Rows.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.