Table.AddKey

Syntax

Table.AddKey(table as table, columns as list, isPrimary as logical) as table

About

Adds a key to table, where columns is the list of column names that define the key, and isPrimary specifies whether the key is primary.

Example 1

Add a single-column primary key to a table.

Usage

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"]
})