Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Google Sheets Sort by One Column Then Another Guide

· 7 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To sort by one column and then another in Google Sheets, use the Data > Sort range > Advanced range sorting options menu. This allows you to define a primary sort column and add additional levels of sorting for any ties in the first column, ensuring your data remains organized across multiple categories.

Multi-level sorting is essential when you have a dataset where a single column contains many duplicate values. For example, if you are sorting a list of employees by "Department," you will likely have dozens of people in the "Sales" department. Without a second sort level, those Sales employees will appear in a random order. By adding a second sort level for "Last Name," you ensure that every department is alphabetized, and within each department, the employees are also alphabetized. This creates a professional, readable hierarchy that makes data analysis significantly faster.

What You'll Need

  • A Google account with access to Google Sheets.
  • A dataset containing at least two columns of data.
  • A desktop web browser (the advanced sorting menu is more robust on desktop than the mobile app).
  • A clear understanding of which column should take priority (the primary sort) and which should act as the tie-breaker (the secondary sort).

Step-by-Step

  1. Highlight Your Data: Click and drag your mouse to select the entire range of data you wish to sort. It is critical to select all columns associated with your records; if you only select the column you want to sort, you will scramble your data, and the rows will no longer match their original records. If your data occupies the entire sheet, you can click the empty rectangle in the top-left corner (above row 1 and to the left of column A) to select everything.
  2. Open the Sort Menu: Navigate to the top menu bar and click on Data. From the dropdown menu, hover over Sort range. A side menu will appear; click on Advanced range sorting options. Note that labels and menu positions may differ slightly depending on your browser version or region.
  3. Handle Header Rows: In the dialog box that appears, look for the checkbox labeled Data has header row. If your first row contains titles (like "Date," "Name," or "Amount"), check this box. This tells Google Sheets to ignore the first row during the sort process so that your headers stay at the top and aren't sorted into the middle of your data.
  4. Set the Primary Sort: Under the Sort by dropdown, select the column that represents your most important category. For example, if you want to group by "Region" first, select the Region column. Choose either A → Z (ascending) or Z → A (descending) based on your preference.
  5. Add the Secondary Sort: Click the button labeled Add another sort column. A second dropdown menu will appear below the first one. Select the column you want to use as the tie-breaker. For example, if you sorted by "Region" first, you might now select "Sales Amount" to see the highest performers within each region.
  6. Define the Secondary Order: Choose the sort order for this second column. If you chose "Sales Amount," you would likely select Z → A to list the highest numbers first.
  7. Add Further Levels (Optional): You can repeat the "Add another sort column" process for a third, fourth, or fifth level of sorting if your data is highly complex. Google Sheets will process these in the order they are listed from top to bottom.
  8. Execute the Sort: Once all your levels are defined, click the Sort button. Your data will now be reorganized based on the hierarchy you created.

Common Mistakes

One of the most frequent errors users make is failing to select the entire data range. If you only highlight Column A and perform a sort, Google Sheets may only move the cells in that specific column, effectively detaching the data in Column A from the corresponding data in Columns B, C, and D. This results in corrupted data that is nearly impossible to fix without using the "Undo" (Ctrl+Z) command immediately. Always ensure your entire table is highlighted.

Another common mistake is forgetting to check the "Data has header row" box. When this is left unchecked, Google Sheets treats your headers as regular data. This means your "Name" header might end up sorted alphabetically under the letter "N" in the middle of your list, while a random piece of data moves to the top of the sheet. This disrupts the visual organization and can confuse other users viewing the document.

Users also frequently confuse the order of sorting levels. It is important to remember that the top-most column in the Advanced Sort menu is the "Master" sort. The second column only affects the order of rows that have identical values in the first column. If every entry in your primary sort column is unique, the secondary sort will have no visible effect on your data because there are no "ties" to break.

Tips

To make your sorted data more readable, consider using Alternating Colors. After sorting, go to Format > Alternating colors. This applies a light shading to every other row, which helps the eye track across the screen and makes it easier to see where one sorted group ends and another begins.

If you find yourself sorting the same columns frequently, consider using a Filter View. By going to Data > Filter views > Create new filter view, you can save specific sorting and filtering configurations. This allows you to toggle between different views of your data without permanently changing the layout for other collaborators on the sheet.

For those who are comfortable with formulas, the =SORT() function is a powerful alternative. Instead of using the menu, you can use a formula like =SORT(A2:D100, 1, TRUE, 2, FALSE). In this example, A2:D100 is the range, 1 is the first column to sort (ascending), and 2 is the second column to sort (descending). The advantage of the formula method is that it is dynamic; if you add new data to the original range, the sorted list updates automatically.

Troubleshooting

If your data did not sort as expected, first check for hidden spaces. A common issue in Google Sheets is "trailing spaces"—where a cell contains "Sales " instead of "Sales". To the human eye, they look identical, but Google Sheets sees the space as a character, which will cause those rows to be sorted differently than the clean entries. You can fix this by using the =TRIM() function on your columns before sorting.

If the sort seems to ignore certain rows, check for merged cells. Google Sheets cannot sort ranges that contain merged cells. If you have merged cells across rows or columns within your selection, the sort function will often return an error or fail to move the merged blocks correctly. You must unmerge all cells in the range before applying a multi-level sort.

If the sort is not applying to the entire row, verify that you didn't accidentally select only a partial range. If you see some columns moving while others stay stationary, you have a selection error. Press Ctrl+Z to undo the sort, click the top-left corner of the sheet to select everything, and try the Advanced range sorting options again.

Lastly, if the sort order is inverted, double-check your A → Z versus Z → A settings. Remember that for numbers, A → Z means smallest to largest, and Z → A means largest to smallest. For dates, A → Z is oldest to newest.

Frequently Asked Questions

Can I sort by three or more columns?

Yes. In the Advanced range sorting options menu, you can click "Add another sort column" as many times as needed to create a deep hierarchy of sorting levels.

Will sorting my data delete any information?

No, sorting only changes the visual order of the rows. It does not delete or overwrite any data, provided you have selected the entire range to keep your rows intact.

How do I undo a sort if I made a mistake?

The fastest way to undo a sort is to use the keyboard shortcut Ctrl+Z (Windows) or Cmd+Z (Mac). If you have already closed the document, you can use File > Version history > See version history to restore the sheet to a state before the sort was applied.

Does the sort order affect formulas in my sheet?

If your formulas use absolute cell references (like =$A$2), they will still point to that specific cell regardless of where the data moves. However, if you have formulas that rely on the relative position of data (like =A2+B2), the formulas will move with the row, maintaining the correct calculation for that specific record.

Can I sort by color instead of values?

The Advanced sort menu is designed for values. To sort by color, you should use a Filter. Click Data > Create a filter, click the filter icon in the column header, and select Sort by color.