Table.SelectColumns
Syntax
Table.SelectColumns(table as table, columns as any, optional missingField as nullable number) as table
About
Returns the table
with only the specified columns
.
table
: The provided table.columns
: The list of columns from the tabletable
to return. Columns in the returned table are in the order listed incolumns
.missingField
: (Optional) What to do if the column does not exist. Example:MissingField.UseNull
orMissingField.Ignore
.
Example 1
Only include column [Name].
Usage
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"
)
Output
Table.FromRecords({
[Name = "Bob"],
[Name = "Jim"],
[Name = "Paul"],
[Name = "Ringo"]
})
Example 2
Only include columns [CustomerID] and [Name].
Usage
Table.SelectColumns(
Table.FromRecords({[CustomerID = 1, Name = "Bob", Phone = "123-4567"]}),
{"CustomerID", "Name"}
)
Output
Table.FromRecords({[CustomerID = 1, Name = "Bob"]})
Example 3
If the included column does not exist, the default result is an error.
Usage
Table.SelectColumns(
Table.FromRecords({[CustomerID = 1, Name = "Bob", Phone = "123-4567"]}),
"NewColumn"
)
Output
[Expression.Error] The field 'NewColumn' of the record wasn't found.
Example 4
If the included column does not exist, option MissingField.UseNull
creates a column of null values.
Usage
Table.SelectColumns(
Table.FromRecords({[CustomerID = 1, Name = "Bob", Phone = "123-4567"]}),
{"CustomerID", "NewColumn"},
MissingField.UseNull
)
Output
Table.FromRecords({[CustomerID = 1, NewColumn = null]})
Phản hồi
https://aka.ms/ContentUserFeedback.
Sắp ra mắt: Trong năm 2024, chúng tôi sẽ dần gỡ bỏ Sự cố với GitHub dưới dạng cơ chế phản hồi cho nội dung và thay thế bằng hệ thống phản hồi mới. Để biết thêm thông tin, hãy xem:Gửi và xem ý kiến phản hồi dành cho