I have a list of time seasons within school years:
"Fall 12-13",
"Winter 12-13",
"Spring 12-13",
"Fall 13-14",
etc.
I want to sort a large number of rows chronologically based on these values. In Excel it is possible to sort by a custom list where I simply input the order that I want the items to be sorted by.
I need that same functionality in Power Query but I have not yet figured out how to do this. I have only been able to set sort order to Order.Ascending
or Order.Descending
.
Is there a good way to implement sort-by-custom-list in Power Query?
You can sort a table in Power Query by one column or multiple columns. For example, take the following table with the columns named Competition, Competitor, and Position. Table with Competition, Competitor, and Position columns.
Sorting will be easy. Click dropdown of the column and choose Sort Ascending in Query Editor. We also can add an index to keep the new order.
The second argument to Table.Sort can also be a function: either a function that takes two rows and returns an ordering between them (a la strcmp) or a function that takes a single row and returns the value that should be used for comparisons. So one way to sort the values you describe would be to say
= Table.Sort(Table, each List.PositionOf({"Fall 12-13", "Winter 12-13", "Spring 12-13", "Fall 13-14"}, [Column]))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With