Reputation: 781
How to get type for specified ColumnName in Table?
Example: How to get type text
for column FirstName
:
Table code:
= Table.FromRows(
{
{1, "Bob", "Smith", "123-4567"},
{2, "Jim", "Brown", "987-6543"},
{3, "Paul", "Wick", "543-7890"}
},
{"CustomerID", "FirstName", "LastName", "Phone"}
)
P.S. Solution as function strongly appreciated! :)
Related Topics:
Upvotes: 2
Views: 3493
Reputation: 488
Here's how I get a table type
for the passed in table.
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
)
Then you can use it to simplify grouping rows.
Table.Group(
Source,
listOfCols,
{{"Rows", each _, GetTableType(Source)}}
)
Upvotes: 0
Reputation: 781
Use combination of Type.TableColumn and Value.Type functions:
Type.TableColumn(Value.Type(TableName),ColumnName)
Upvotes: 3