Power Query:按自定义列表排序 [英] Power Query: sort by custom list
问题描述
我有一个学年内的季节列表:
I have a list of time seasons within school years:
"Fall 12-13",
"Winter 12-13",
"Spring 12-13",
"Fall 13-14",
etc.
我想根据这些值按时间顺序对大量行进行排序.在 Excel 中,可以按自定义列表进行排序,我只需输入我希望对项目进行排序的顺序.
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.
我需要 Power Query 中的相同功能,但我还没有想出如何做到这一点.我只能将排序顺序设置为 Order.Ascending
或 Order.Descending
.
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
.
是否有在 Power Query 中实现 sort-by-custom-list 的好方法?
Is there a good way to implement sort-by-custom-list in Power Query?
推荐答案
Table.Sort 的第二个参数也可以是一个函数:接收两行并返回它们之间的排序的函数(a la strcmp)或接受单行并返回应该用于比较的值的函数.因此,对您描述的值进行排序的一种方法是说
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]))
这篇关于Power Query:按自定义列表排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!