Welcome to Excel Jet Consult blog post. In this tutorial, we will learn how to deploy the Table.Sort Table.Sort Power Query M Function to sort multiple columns. Let’s get started
Table.Sort sorts columnar data in table using the list of one or more column names and optional comparison criteria in the form of {{col1, comparisonCriteria),{col2})
Table.Sort Syntax =Table.Sort(table, comparisonCriteria)
In the caption below, we want to sort the Account Manager and Product Category in Ascending and Descending Order respectively
Note, it is required to turn on the formula bar to use the Table.Sort function.
In the Layout group of the View tab, check the Formula Bar box
In the formula bar, execute the syntax:
= Table.Sort(Table.RemoveColumns(#”Changed Type”,{“Customerv Address”, “City”, “State”, “ProductID”, “Product Name”, “Ship Mode”, “Ship Name”}), {{“Account Manager”,Order.Ascending},{“Product Category”,Order.Descending}})
In the above syntax, I typed the Table.Sort with open parenthesis and placed a comma after the last close bracket of the Table.RemoveColumns. Furthermore, I deployed two curly braces and specified the columns inside double quote, to sort on in ascending and descending order respectively. Finally, I closed the bracket for the Table.Sort and clicked Enter
In the caption above, we can see that Account Manager and Product Category are sorted in Ascending and Descending Order respectively