我想要
groupby and rank
示例数据集。 在使用 Factor and YearNum
对数据集进行排名之前,我根据 = Table.AddRankColumn(#"previousStep","RankbyYear_WithInTheFactorLevel",{"YearNum",Order.Descending})
对数据集进行分组,但似乎它无法识别电力查询中的上一步。有办法解决这个问题吗?非常感谢。
样本数据集
Factor YearNum Col1 Col2 ....
A 2024
A 2024
A 2025
B 2024
B 2023
预期答案
Factor YearNum Col1 Col2 .... RankbyYear_WithInTheFactorLevel
A 2024 2
A 2024 2
A 2025 1
B 2024 1
B 2023 2
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Factor", type text}, {"YearNum", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Factor"}, {{"All", each _, type table [Factor=nullable text, YearNum=nullable number]}}),
Custom1 = Table.TransformColumns( #"Grouped Rows", {{"All", each Table.AddRankColumn( _, "rank", {{"YearNum", Order.Descending}} )}}),
#"Expanded All" = Table.ExpandTableColumn(Custom1, "All", {"YearNum", "rank"}, {"YearNum", "rank"})
in
#"Expanded All"