OpenBI Docs Buy

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
ParameterTypeDescription
tabletableThe table to give the key.
columnslistThe key's columns, by name.
isPrimarylogicaltrue for the table's primary key.

Returns

table. The same rows, with the key added to the table's keys.

Remarks

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

Table.Keys, Table.ReplaceKeys, Table.Distinct, Table.IsDistinct.

Last updated · OpenBI Studio 0.3.79