Forum Discussion
Power Query - automatically change type of data inside the column (columns have changing titles)
- Jan 03, 2022
To change #1 and #3 on text and rest on whole number
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], columnNames = Table.ColumnNames( Source ), changeType = Table.TransformColumnTypes( Source, List.Transform( columnNames, each if List.PositionOf(columnNames, _) = 0 or List.PositionOf(columnNames, _) = 2 then {_, type text} else {_, Int64.Type} ) ) in changeTypeNames of columns and their number don't matter.
I also use the imported table shown in description of this discussion in futher calculations (there are fomulas in different sheets that take data from this table) . But of course every day, when I update main table with PQ (every day source file changes) - all the formulas in my file break down (have "#ARG" mistake). Is there a way to avoid this kind of mistake so that formulas in other sheets work properly after I update main table?
Thank you so much for helping me.
- PeterBartholomew1Jan 04, 2022Silver Contributor
I played with this a bit before lunch. You have to know the name of the Table, but you can get away with not knowing the column names (as SergeiBaklan suggests).
"Dates" = INDEX(Table1[#Headers], 3+day) "Values" = INDEX(Table1, 0, 3+day)With 365 that can be dressed up a bit with Lambda functions, to give
"Date" = Dateλ(day) "Values" = Valuesλ(Dateλ(2))where 'Valuesλ' refers to
= LAMBDA(dd, XLOOKUP(dd, Table1[#Headers], Table1) )- SergeiBaklanJan 04, 2022Diamond Contributor
PeterBartholomew1 , hope this exercise didn't affect you appetite.
Carminol , it's better to have sample file to be more concrete in our suggestions.
- SergeiBaklanJan 04, 2022Diamond Contributor
If I understood correctly table returned by Power Query has different headers after each daily update, formulae in sheet do not recognize these new headers.
If so, in any case you shall identify somehow columns in main table. That could be by name or by position.
If by name you may use pre-defined column names and change on them in Power Query ignoring column names in source file.
If by position most probably you shall re-write formulae to work with column positions.