如何获取Table中指定ColumnName的类型?
示例:如何获取第
type text
列的FirstName
:
表代码:
= Table.FromRows(
{
{1, "Bob", "Smith", "123-4567"},
{2, "Jim", "Brown", "987-6543"},
{3, "Paul", "Wick", "543-7890"}
},
{"CustomerID", "FirstName", "LastName", "Phone"}
)
附注解决方案作为功能强烈赞赏! :)
相关主题:
请尝试此功能
sfnClmType
(下载):
(TableName as table, ColumnName as text) =>
let valTypeTxt = Table.SelectRows(Table.Schema(TableName), each [Name] = ColumnName){0}[Kind]
in Expression.Evaluate("type "& valTypeTxt)
相关主题:
使用 Type.TableColumn 和 Value.Type 函数的组合:
Type.TableColumn(Value.Type(TableName),ColumnName)
这是我如何为传入的表获取
table type
。
GetTableType = (tbl as table) as type =>
let
colNames = Table.ColumnNames(tbl),
colTypes = List.Transform(
colNames,
(x) => [Type=Value.Type(Table.Column(tbl, x)), Optional=false]
)
in
type table Type.ForRecord(
Record.FromList(
colTypes,
colNames
),
false
)
然后您可以使用它来简化行分组。
Table.Group(
Source,
listOfCols,
{{"Rows", each _, GetTableType(Source)}}
)