Table.ReplaceKeys

Table.ReplaceKeys is a Power Query M function that replaces the keys of a specified table. The function returns a new table with the keys replaced.

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

Syntax

Table.ReplaceKeys(
   table as table,
   keys as list,
) as table

Description

Replaces the keys of the specified table.

Examples

Replace the existing keys of a table.

let
    table = Table.FromRecords( {
        [Id = 1, Name = "Hello There"],
        [Id = 2, Name = "Good Bye"]
    } ),
    tableWithKeys = Table.AddKey( table, {"Id"}, true ),
    resultTable = Table.ReplaceKeys( tableWithKeys, {[Columns = {"Id"}, Primary = false]} )
in
    resultTable

 /* Output: 
Table.FromRecords( {
    [Id = 1, Name = "Hello There"],
    [Id = 2, Name = "Good Bye"]
} )
 */ 

Other functions related to Table.ReplaceKeys 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-replacekeys
© 2023 BI Gorilla. All rights reserved. Content derived from Microsoft documentation is property of Microsoft Corp.