Get instant live expert help with Excel or Google Sheets
“My Excelchat expert helped me in less than 20 minutes, saving me what would have been 5 hours of work!”

Post your problem and you’ll get expert help in seconds.

Your message must be at least 40 characters
Our professional experts are available now. Your privacy is guaranteed.

Instructions for Sorting a Pivot Table by Two Columns

A pivot table in Excel is an excellent tool for analyzing data. It helps you to aggregate, summarize, finding insights and present a large amount of data in a few clicks. It is also very flexible and can be changed without much effort. You can sort a large amount of data very easily using pivot tables. In this tutorial, we will see how to sort a pivot table based on two or more columns.

Sorting a Pivot Table by Two Columns

In this example, you will use the quarterly sales data of Jingo Juice corner. The data consists of quantity and sales for beverages during the 2nd quarter of the year through four states.

The pivot table aggregates the items based on months and shows the sales. The original data had 133 entries which are summarized very efficiently with the pivot table.

Sorting a Pivot Table

You can sort a pivot table in ascending or descending order like any other tables. You can sort the labels and the fields. To sort the labels, you click on the filter icon beside it. From there, select “sort A to Z” or “sort Z to A” to sort in ascending or descending order. To sort any pivot table field, you need to click anywhere in the column and click sort in the Data tab in the ribbon and select how you want to sort.

If you wanted to sort the labels in descending order:

  • Click the filter icon beside “Row labels”.
  • Select “sort Z to A”.

This will show the items in descending order. You can also select “More sort options” to fine-tune your sorting.

To sort the table based on the sales in May in descending order, you would need to perform the following steps:

  • Click on cell E6.
  • Click on Data > Sort.
  • Select “Largest to Smallest” as sort option and “Top to Bottom” as Sort direction.

  • Click OK.

This would rearrange the table based on the sales in May in descending order.

Sort Two columns in Pivot Table

Normally, it is not possible to sort a pivot table based on two columns. However, with a workaround adding a calculated field, it is possible to sort two columns in a pivot table.

For this example, you will use the order data for the beverages from the previous example. The data contains the beverage ID, name and total orders.

The pivot table shows the Item names, order count and total orders.

This is the pivot table. If you wanted to sort it by “Count of Orders” first and then by “Sum of Orders” in descending order, you would need to perform the following steps:

  1. At first, you would need to add an extra column to your data table. Name it “Count.” Set the value of cell E2 to 1 and drag it down to the cells below.

  2. Click anywhere on the pivot table.
  3. Go to Analyze > Fields, Items and Sets > Calculated Fields.
  4. On the name field Type “Rank,”, on the formula field insert the formula using the “Insert field” button.“=(Count * 1000) + (Orders/1000)”

  5. Click OK.

  6. Now the calculated fields will have the desired ranks. To sort it select the cells D4:D9. Go to Data > (Sort) Z – A. This will sort the pivot table in the desired way. Now to hide the rank column right click on the column name on top and select Hide.

Sorting Excel tables with Power Pivot

Power pivot is an add-in for Excel used to perform powerful data analysis, data modeling and gather business insights. It can handle large volumes of data from different sources in a single Excel file.

Power pivot is built into certain versions of Office, but to use it you have to enable it at first. To do that:

  1. Go to File > Options > Add-Ins.
  2. Click COM Add-ins in the Manage box > Click Go.
  3. Check the box for Microsoft Office Power Pivot > click OK. Select the Power Pivot add-in for Excel if you have other versions of Power pivot installed.

Power pivot has a great option to sort: Sort by column. In order to use Power pivot, at first you need to add your data to the data model. To do that, from your worksheet,

Click on Power pivot > Add to Data Model. Check if the range matches your data and click “My table has headers.”

For this example, we will use the popular ranked beverages from the previous example. It has the beverage names and their rank based on popularity. You will sort the beverages based on the rank. To do this:

  1. On the power pivot window click PivotTable. Check New worksheet and click OK. Now in the pivot table, set the “Items” as row and “Rank” as values.

  2. Go back to the power pivot window. Select cells 1:11 having the item names and go to Home > Sort by Column.
  3. Set “Items” as the sort column and “Rank” as the By column.

  4. Click Ok.

This will sort the items based on ranks in the pivot table.

Power Pivot can sort multiple columns as well which is a lot simpler than sorting in pivot tables. Pivot tables are a great way to summarize and aggregate data to model and present it. Power Pivot is also another great tool to gain business insights.

There are many interesting features of Pivot Table and Power Pivot that could help you gain insights into your data. If you want to save hours of researching and frustration and get to the solution quickly, try our Excel Live Chat service! Our Excel experts are available 24/7 to answer any Excel question you have on the spot. The first question is free.

Did this post not answer your question? Get a solution from connecting with the expert.

Another blog reader asked this question today on Excelchat:

Leave a Comment

avatar

Subscribe to Excelchat.co

Get updates on helpful Excel topics

Subscribe to Excelchat.co

Did this post not answer your question?
Get a solution from connecting with the expert

Another blog reader asked this question today on Excelchat:

Post your problem and you’ll get expert help in seconds.

Your message must be at least 40 characters
Our professional experts are available now. Your privacy is guaranteed.
Trusted by people who work at
Amazon.com, Inc
Facebook, Inc
Accenture PLC
Siemens AG
Macy's
The Allstate Corporation
United Parcel Service
Dell Inc