Table.Keys
Lists the keys a table has been given, each as a record of its columns and whether it is primary.
Group: Table. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
Table.Keys(table as table) as list
| Parameter | Type | Description |
|---|---|---|
table | table | The table to look at. |
Returns
list. One record [Columns = {...}, Primary = ...] per key; an empty list when the table has none.
Examples
A table without keys
Table.Keys(#table({"Product", "Price", "Units"}, {{"Chair", 50, 4}, {"Desk", 120, 1}, {"Lamp", 30, 6}}))
{}
After two keys are added
let
Lines = #table({"Product", "Price", "Units"}, {{"Chair", 50, 4}, {"Desk", 120, 1}, {"Lamp", 30, 6}}),
Keyed = Table.AddKey(Table.AddKey(Lines, {"Product"}, true), {"Price", "Units"}, false)
in
Table.Keys(Keyed)
{[Columns = {"Product"}, Primary = true], [Columns = {"Price", "Units"}, Primary = false]}