top of page

You are learning Power Query in MS Excel

How to sort data by one or more columns in Power Query?

There are two main ways to sort data by one or more columns in Power Query:

1. Using the User Interface (UI):

* Select the column(s) you want to sort by. You can hold Ctrl and click on multiple columns for multi-column sorting.
* Click the down arrow next to the chosen column header.
* - Choose "Sort Ascending" to sort from A to Z (smallest to largest for numbers)
* - Choose "Sort Descending" to sort from Z to A (largest to smallest for numbers)
* Repeat for additional sorting criteria by clicking the down arrow on the next column header and selecting the desired sort order.

2. Using the M Language:

* In the Power Query Editor, navigate to the "Home" tab and click "Transform" > "Advanced" > "Sort."
* This will open the "Sort" window.
* In the "Column" dropdown, select the first column you want to sort by.
* Choose "Ascending" or "Descending" for the sort order.
* If you want to sort by multiple columns, click "Add Sort By" and repeat the process for each additional column.

Here are some additional points to consider:

* Sorting happens in the order you define the columns. The first selected column will be sorted first, then the second, and so on.
* You can use the "Custom Order" option in the "Sort" window to define a specific sorting order for text values that may not be alphabetical by default (e.g., custom product codes).
* Power Query sorts by default based on the data type of the column. Numbers are sorted numerically, text is sorted alphabetically, and dates are sorted chronologically.

bottom of page