Table.AddKey
Marks one or more columns as a key of the table: their values are said to tell the rows apart.
Group: Table. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
Table.AddKey(table as table, columns as list, isPrimary as logical) as table
| Parameter | Type | Description |
|---|---|---|
table | table | The table to give the key. |
columns | list | The key's columns, by name. |
isPrimary | logical | true for the table's primary key. |
Returns
table. The same rows, with the key added to the table's keys.
Remarks
- The key is a statement about the table: the rows are not checked, and duplicates stay.
Table.Distinctremoves them,Table.IsDistinctchecks. Table.Keyslists a table's keys.
Examples
A primary key on Product
let
Lines = #table({"Product", "Price", "Units"}, {{"Chair", 50, 4}, {"Desk", 120, 1}, {"Lamp", 30, 6}})
in
Table.Keys(Table.AddKey(Lines, {"Product"}, true))
{[Columns = {"Product"}, Primary = true]}
Related functions
Table.Keys, Table.ReplaceKeys, Table.Distinct, Table.IsDistinct.