Forum Discussion
help to transform a table on Powerquerry
- 1 year ago
I need further assistance since I've made more changes at the file. So It is not enough to copy the code and paste it (because it will clean all previous steps done by me).
Hi jps_HHH , another solution for you to look at. Thanks. Also, what would I mention is, that if you can possibly provide static column names to it rather than Column1, it would be great since it would allow you to split automatically without manually typing in the number 4. It'll pick up the distinct count of columns and use that. Here, I have given certain names to the columns for you reference.
Here's the code:
let
Source = Excel.CurrentWorkbook(){[Name="Table6"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}, {"Column3", type text}, {"Column4", type text}, {"Column5", type text}, {"Column6", type text}, {"Column7", type text}, {"Column8", type text}}),
ColNames = List.Distinct ( Record.ToList( #"Changed Type"{0} ) ),
Number = List.Count ( ColNames ),
Splitting = List.Split ( Table.ToColumns ( #"Changed Type" ) , Number ),
Table = List.Transform ( Splitting , each Table.PromoteHeaders ( Table.FromColumns ( _ ) ) ),
Combined = Table.Combine ( Table )
in
Combined