英文:
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"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论