Course / Sort and filter

Sort by two columns

Group a table by region with the best sale first in each, by sorting twice in the right order. Beginner · 4 min · Two-level sort, Sort order, Groups

One column is often not enough. By region, and within each region the biggest sale first is a sort on two columns.

The trick is that a sort keeps the order it finds among rows that tie. So sort twice, starting with the less important column:

1. First by Sales, largest first. 2. Then by Region.

After the second sort, the regions are together, and inside each one the sales are still in the order the first sort left them.

In Excel, you can do the same in one go with Data → Sort, adding a level for each column. The most important column goes first there, which is the reverse of the order you click the buttons in.

Steps

  1. Start with the less important column. Click a cell in Sales, such as C2, then Sort Z to A (the Z→A button in the toolbar).

  2. Now the more important one. Click a cell in Region, such as A2, then Sort A to Z (the A→Z button in the toolbar).

  3. Your turn, the other way up: group the table by Region from Z to A, with the smallest sale first in each region.

Remember

Previous: Sort a table · Next: Filter a table