Table.ReplaceKeys
Sets a table's keys, in place of any it had.
Group: Table. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
Table.ReplaceKeys(table as table, keys as list) as table
| Parameter | Type | Description |
|---|---|---|
table | table | The table to give keys. |
keys | list | The keys, each a record with Columns (a list of column names) and Primary (true or false); an empty list leaves the table without keys. |
Returns
table. The same rows and columns, with these keys.
Remarks
- Keys describe the table: the rows are not checked for repeats.
Table.Keysreads the keys;Table.AddKeyadds one to those there.
Examples
A key of two columns
let
Lines = #table({"Order", "Line", "Product"}, {{1, 1, "Chair"}, {1, 2, "Desk"}})
in
Table.Keys(Table.ReplaceKeys(Lines, {[Columns = {"Order", "Line"}, Primary = true]}))
{[Columns = {"Order", "Line"}, Primary = true]}
No keys any more
Table.Keys(Table.ReplaceKeys(Table.AddKey(#table({"Id"}, {{1}}), {"Id"}, true), {}))
{}