

February 1, 2019

hi Guys,
i am using this code to change all columns of table to type "text":
Table2 query:
let
Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
#"Changed Type" = List.Accumulate(Table.ColumnNames(Source), Source, (state, current) => try Table.TransformColumnTypes(state,{{current, type text}}) otherwise state)
in
#"Changed Type"
But what i have to is to provide exactly from another table column types and use it in function to get proper columns types in Table2.
ColumnTypes table:
TableNameColNameColumnType
Table2 | Col1 | text |
Table2 | Col2 | Int64.Type |
Table2 | Col3 | number |
So from this table i have to get that Col1 is text, Col2 is Int64.Type and apply into my query for Table2.
How can i achieve this ?
Thank you for help,
Jacek


February 1, 2019

Hello,
i am getting back with function:, something like:
let
TabName = "Table2",
ColName = "Col2",
Source = ColumnTypes,
#"Filter" = Table.SelectRows(Source, each ([TableName] = TabName and [ColumnName]= "Name")){0}[ColumnType]
in
#"Filter"
the issue is that now i have to do something similar but from string:
{"DiskSize",Int64.Type}, {"DiskSizeGiB",type text} - i have exact strings in table which i should use as columns.
Could i read the string and put in ChangedType statement somehow?
Best,
Jacek

New Member

November 28, 2022

What do I need to change in solution of #7 to make it work for the other types?
#"Changed Type" = Table.TransformColumnTypes(Source,{ |
{"Col_a", type number}, |
{"Col_b", Currency.Type}, |
{"Col_c", Int64.Type}, |
{"Col_d", Percentage.Type}, |
{"Col_e", type datetime}, |
{"Col_f", type date}, |
{"Col_g", type time}, |
{"Col_h", type datetimezone}, |
{"Col_i", type duration}, |
{"Col_j", type text}, |
{"Col_k", type logical}, |
{"Col_l", type binary}}) |
1 Guest(s)
