Smart Systems for Home

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

Excel Power Query: How to Sort Data Step by Step

· 5 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 data in Excel Power Query, load your table into the Power Query Editor (Data > From Table/Range), click the drop-down arrow on the column header you want to sort by, and choose Sort Ascending or Sort Descending. Power Query applies the sort as a step in the Applied Steps pane, so it repeats automatically every time the query refreshes. You can add more sort levels by right-clicking a second column and choosing the sort option, or by using the Sort dialog under the Home tab. Note that menu labels and button positions can differ slightly between Excel versions and regions.

What You'll Need

  • Excel with Power Query built in (Excel 2016 and later on Windows; Excel for Microsoft 365 on Mac). In older versions, Power Query is an add-in you enable first.
  • A data source already formatted as a table (select your range and press Ctrl+T) or an external connection.
  • Basic familiarity with the Power Query Editor window and the Applied Steps pane on the right.

Step-by-Step

  1. Load your data into Power Query. Select any cell in your table, then go to Data > From Table/Range. If your data is external (a CSV, database, or web page), use the matching connector under the Data tab instead. The Power Query Editor opens in a separate window.
  2. Identify the column to sort by. In the Editor, find the column header in the data preview. Each header has a small drop-down arrow on its right edge.
  3. Apply a basic sort. Click the drop-down arrow on the column header and choose Sort Ascending (A to Z, smallest to largest) or Sort Descending (Z to A, largest to smallest). The data reorders immediately and a new step such as Sorted Rows appears in the Applied Steps pane.
  4. Add a second sort level (multi-column sort). For a stable sort with a tie-breaker, use the dialog instead: go to Home > Sort > Sort... (or right-click the column and choose Sort). In the Sort dialog, set the first column and direction, click Add Level, then set the second column and direction. Confirm with OK.
  5. Sort by a custom list (optional). If you want a specific order such as Monday through Sunday, right-click the column, choose Sort > Sort by List... and pick or define the list. This is useful for text categories that do not sort alphabetically the way you want.
  6. Check the Applied Steps pane. Confirm the sort step sits in the right position. Steps run top to bottom, so a sort placed before a filter or merge only sorts that earlier stage. Drag steps up or down if needed, or delete a step with the X to its left.
  7. Close and load. Go to Home > Close & Load to send the sorted result to a worksheet or the Data Model. The sort now refreshes with the query.

Common Mistakes

  • Sorting in the worksheet instead of the query. A manual Excel sort is lost on refresh. Always sort inside the Power Query Editor so the step is saved.
  • Sorting before filtering or merging. Because steps run in order, a sort placed too early may not affect the final output. Move the sort step to the end of the chain.
  • Expecting a sort to fix data types. If a number column is stored as text, ascending sort puts "10" before "2". Change the data type to Whole Number or Decimal Number first.
  • Forgetting that sorts are not case- or locale-aware in every case. Text sorting follows the query's locale settings, so accented characters and mixed case can land in unexpected places.
  • Assuming the first row is a header. If your source has no headers, promote the first row to headers before sorting, or the header text gets sorted into the data.

Tips

  • Use the Sort dialog rather than the header drop-down when you need more than one sort level; it keeps the logic in a single, readable step.
  • Rename the sort step in the Applied Steps pane (right-click > Rename) so future you knows why it is there.
  • If you only need the top rows, sort first and then use Home > Keep Rows > Keep Top Rows.
  • Sorting is applied to the whole query result, not a visible selection, so you do not need to select cells first.
  • For large queries, sorting adds processing time on every refresh; place it as late as possible and remove it if the order is not actually needed.

Troubleshooting

  • The sort looks wrong for numbers. Check the column's data type icon in the header. If it shows ABC (text), click the icon and choose the numeric type, then reapply the sort.
  • The sort step is greyed out or missing. Make sure you are in the Power Query Editor, not the worksheet, and that a column is selected. If the query is a parameter or a function, sorting may not be available.
  • Refreshing in Excel undoes the order. The worksheet output is a snapshot; if someone manually re-sorted the loaded table, refresh restores the query's order. Sort in the query, not the sheet.
  • Headers appear as data after sorting. Use Home > Use First Row as Headers before sorting, then reapply.
  • The query errors after adding a sort. Look at the error message in the step; it usually points to a type mismatch. Change the data type in the step before the sort.
  • If that did not work, delete the sort step, close without saving changes if prompted, and rebuild the query from the source. If the file itself is corrupted, open a fresh workbook and reconnect to the source.

Frequently Asked Questions

Does sorting in Power Query change my original data?

No. Power Query works on a copy of the data. The source table, file, or database is untouched; only the query output is reordered.

Can I sort by more than one column?

Yes. Use Home > Sort > Sort... and click Add Level for each additional column, choosing ascending or descending per level.

Why does my sort reset when I refresh?

If the order was changed manually in the worksheet, refresh restores the query's saved sort. Apply the sort inside the Power Query Editor so it persists.

Can I sort by a custom order like month names?

Yes. Right-click the column, choose Sort > Sort by List... and select or define the order you want.

Does Power Query sort case-sensitively?

Text sorting follows the query's locale and comparison settings, so mixed case and accented characters may not sort the way you expect. Check the column's type and locale if the order looks odd.

Is sorting available in Power Query on Mac?

Yes, the Power Query Editor in Excel for Microsoft 365 on Mac includes sorting via the column header drop-down and the Sort dialog, though some labels may differ from Windows.