在第n个位置添加PowerQuery列。

huangapple go评论62阅读模式
英文:

Powerquery add column in the n'th position

问题

我想在第三个位置(顺序)添加一列。有办法做到吗?

#Reordered Columns = Table.ReorderColumns(TotalSum, {"Bütçe Kodu", "Bütçe Kalemi", "Total Cost", {{{{其他列名在这里}}}}}

或者在添加后重新排列列,但我有动态列名,所以我需要再次动态地将这个新列移动到第三个位置。

英文:

i want to add a column on the 3th place (order). is there a way to do that ?

TotalSum = Table.AddColumn(#"Pivoted Column", "Total Cost", each List.Sum(Record.FieldValues(Record.SelectFields(_, List.Difference(Table.ColumnNames(#"Pivoted Column"), {"Bütçe Kodu", "Bütçe Kalemi", "Ay-Yıl"} ))))),
#"Reordered Columns" = Table.ReorderColumns(TotalSum,{"Bütçe Kodu", "Bütçe Kalemi", "Total Cost", {{{{ the other column names here }}}}}

or after adding i can reorder the columns but i have a dynamic column names so i need again dynamically move this new column on the 3th place.

thanks

答案1

得分: 2

无法在指定位置添加列。您可以创建新列,然后动态移动它,就像这个例子中将列 e 移动到位置 3

let
    源 = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    x = List.Difference(Table.ColumnNames(源), {"e"}),
    #"重新排序的列" = Table.ReorderColumns(源, List.Combine({List.Range(x, 0, 2), {"e"}, List.Skip(x, 2)}))
in
    #"重新排序的列"
英文:

You can not add a column in a specified position. You can instead create the new column, then dynamically move it, like in this example, moving column e to position 3

let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
x=List.Difference(Table.ColumnNames(Source),{"e"}),
#"Reordered Columns" = Table.ReorderColumns(Source,List.Combine({List.Range(x,0,2),{"e"},List.Skip(x,2)}))
in #"Reordered Columns"

在第n个位置添加PowerQuery列。

huangapple
  • 本文由 发表于 2023年5月7日 19:36:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76193676.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定