Skip to main content

Table.SelectColumns

Returnează un tabel numai cu coloanele specificate.

Syntax

Table.SelectColumns(
table as table,
columns as any,
optional missingField as MissingField.Type
) as table

Remarks

Returnează table numai cu columns specificat.

  • table: tabelul furnizat.
  • columns: Lista de coloane din tabelul table de returnat. Coloanele din tabelul returnat sunt în ordinea listată în columns.
  • missingField: (Opțional) Ce să faceți dacă coloana nu există. Example: MissingField.UseNull sau MissingField.Ignore.

Examples

Example #1

Includeți doar coloana [Name].

Table.SelectColumns(
Table.FromRecords({
[CustomerID = 1, Name = "Bob", Phone = "123-4567"],
[CustomerID = 2, Name = "Jim", Phone = "987-6543"],
[CustomerID = 3, Name = "Paul", Phone = "543-7890"],
[CustomerID = 4, Name = "Ringo", Phone = "232-1550"]
}),
"Name"
)

Result:

Table.FromRecords({
[Name = "Bob"],
[Name = "Jim"],
[Name = "Paul"],
[Name = "Ringo"]
})

Example #2

Includeți doar coloanele [CustomerID] și [Name].

Table.SelectColumns(
Table.FromRecords({[CustomerID = 1, Name = "Bob", Phone = "123-4567"]}),
{"CustomerID", "Name"}
)

Result:

Table.FromRecords({[CustomerID = 1, Name = "Bob"]})

Example #3

Dacă coloana inclusă nu există, rezultatul implicit este o eroare.

Table.SelectColumns(
Table.FromRecords({[CustomerID = 1, Name = "Bob", Phone = "123-4567"]}),
"NewColumn"
)

Result:

[Expression.Error] The field 'NewColumn' of the record wasn't found.

Example #4

Dacă coloana inclusă nu există, opțiunea MissingField.UseNull creează o coloană cu valori nule.

Table.SelectColumns(
Table.FromRecords({[CustomerID = 1, Name = "Bob", Phone = "123-4567"]}),
{"CustomerID", "NewColumn"},
MissingField.UseNull
)

Result:

Table.FromRecords({[CustomerID = 1, NewColumn = null]})

Category

Table.Column operations