Table.DuplicateColumn
Copies a column into a new one with another name, at the end of the table.
Group: Table. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
Table.DuplicateColumn(table as table, columnName as text, newColumnName as text, optional columnType as nullable type) as table
| Parameter | Type | Description |
|---|---|---|
table | table | The table with the column. |
columnName | text | The column to copy. |
newColumnName | text | The copy's name. |
columnType | nullable type optional | The copy's type; the column's own type when left out. |
Returns
table. The table with the copy as its last column.
Remarks
- Handy before a step that changes a column, such as a split, when the original is still needed.
Examples
Keep the original before changing it
let
Lines = #table({"Product", "Price", "Units"}, {{"Chair", 50, 4}, {"Desk", 120, 1}, {"Lamp", 30, 6}}),
Copied = Table.DuplicateColumn(Lines, "Product", "Product code")
in
Table.TransformColumns(Copied, {"Product code", Text.Upper})
| Product | Price | Units | Product code |
|---|---|---|---|
| Chair | 50 | 4 | CHAIR |
| Desk | 120 | 1 | DESK |
| Lamp | 30 | 6 | LAMP |
Related functions
Table.AddColumn, Table.TransformColumns, Table.RenameColumns.