Table.DuplicateColumn

Updated on

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

Table.DuplicateColumn duplicates the column named columnName in the table table. The duplicated column, newColumnName, copies values and type from 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

Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/powerquery-m/table-duplicatecolumn