In Power Query, is there an easy way to add a custom column so that the placement is not always at the very end? for example, if I have 20 columns and I want to place the new column after column 5... Thankyou in advance!
Book1 | ||||||||
---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | |||
1 | Col1 | Col2 | Col4 | Col5 | Col6 | |||
2 | 1 | 2 | 4 | 5 | 6 | |||
3 | 1 | 2 | 4 | 5 | 6 | |||
4 | 1 | 2 | 4 | 5 | 6 | |||
5 | 1 | 2 | 4 | 5 | 6 | |||
6 | 1 | 2 | 4 | 5 | 6 | |||
7 | ||||||||
Sheet2 |
(tbl as table, ColName as text, fnAdd as function, pos as number) =>
let
tbl1 = Table.AddColumn(tbl, ColName, fnAdd),
reorder = let tcn = Table.ColumnNames(tbl1) in List.FirstN(tcn,pos) & {List.Last(tcn)} & List.Range(tcn, pos, List.Count(tcn) - pos -1),
Result = Table.ReorderColumns(tbl1, reorder)
in
Result
let
Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
Result = Table_AddColumnAtPosition(Source,"Col3", each 3, 2)
in
Result
Book1 | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | M | |||
1 | Col1 | Col2 | Col4 | Col5 | Col6 | Col1 | Col2 | Col3 | Col4 | Col5 | Col6 | ||||
2 | 1 | 2 | 4 | 5 | 6 | 1 | 2 | 3 | 4 | 5 | 6 | ||||
3 | 1 | 2 | 4 | 5 | 6 | 1 | 2 | 3 | 4 | 5 | 6 | ||||
4 | 1 | 2 | 4 | 5 | 6 | 1 | 2 | 3 | 4 | 5 | 6 | ||||
5 | 1 | 2 | 4 | 5 | 6 | 1 | 2 | 3 | 4 | 5 | 6 | ||||
6 | 1 | 2 | 4 | 5 | 6 | 1 | 2 | 3 | 4 | 5 | 6 | ||||
7 | |||||||||||||||
Sheet2 |
That's what I was afraid of. Thank you for responding!Not currently, as far as I know. You have to add it, then move it.