Table.AddKey is a Power Query M function that adds a key to a table using a list of column names that define the key, and specifies whether the key is primary. The function returns a new table with the added key.
Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365
Syntax
Table.AddKey(
table as table,
columns as list,
isPrimary as logical,
) as table
Description
Table.AddKey adds a key to table. The key is defined by a list of column names in columns, and isPrimary indicates whether the key is primary.
Examples
Add a single-column primary key to a table.
let
table = Table.FromRecords( {
[Id = 1, Name = "Hello There"],
[Id = 2, Name = "Good Bye"]
} ),
resultTable = Table.AddKey( table, {"Id"}, true )
in
resultTable
/* Output:
Table.FromRecords( {
[Id = 1, Name = "Hello There"],
[Id = 2, Name = "Good Bye"]
} )
*/
Related functions
Other functions related to Table.AddKey are:
2023-2026 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy