Table.DuplicateColumn

Table.DuplicateColumn is a Power Query M function that duplicates a specified column in a table, copying the values and type from the original column. The function returns a new table with the duplicated column.

Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365

Syntax

Table.DuplicateColumn(
   table as table,
   columnName as text,
   newColumnName as text,
   optional columnType as nullable type,
) as table

Description

Duplicate the column named columnName to the table table. The values and type for the column newColumnName are copied from coulmn columnName.

Examples

Duplicate the column “a” to a column named “copied column” in the table ( {[a = 1, b = 2], [a = 3, b = 4]} ).

Table.DuplicateColumn( 
    Table.FromRecords( {
        [a = 1, b = 2],
        [a = 3, b = 4]
    } ),
    "a",
    "copied column"
 )

 /* Output: 
Table.FromRecords( {
    [a = 1, b = 2, #"copied column" = 1],
    [a = 3, b = 4, #"copied column" = 3]
} )
 */ 

Other functions related to Table.DuplicateColumn are:

BI Gorilla Blog

Last update: August 28, 2023 | Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/powerquery-m/table-duplicatecolumn
© 2023 BI Gorilla. All rights reserved. Content derived from Microsoft documentation is property of Microsoft Corp.