Share via


Table.AddKey

Syntax

Table.AddKey(table as table, columns as list, isPrimary as logical) as table

About

Adds a key to table, where columns is the list of column names that define the key, and isPrimary specifies whether the key is primary.

Example 1

Add a single-column primary key to a table.

Usage

let
    table = Table.FromRecords({
        [Id = 1, Name = "Hello There"],
        [Id = 2, Name = "Good Bye"]
    }),
    resultTable = Table.AddKey(table, {"Id"}, true)
in
    resultTable

Output

Table.FromRecords({
    [Id = 1, Name = "Hello There"],
    [Id = 2, Name = "Good Bye"]
})

Additional resources

Training

Module

Add calculated tables and columns to Power BI Desktop models - Training

By the end of this module, you'll be able to add calculated tables and calculated columns to your semantic model. You'll also be able to describe row context, which is used to evaluated calculated column formulas. Because it's possible to add columns to a table by using Power Query, you'll also learn when it's best to create calculated columns instead of Power Query custom columns.