OpenBI Docs Buy

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
ParameterTypeDescription
tabletableThe table to give keys.
keyslistThe 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.Keys reads the keys; Table.AddKey adds 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), {}))
{}

Table.Keys, Table.AddKey.

Last updated · OpenBI Studio 0.3.79