Forum Discussion
Combining files with different column titles
- 5 years ago
Hi deanbland
Download sample PBIX with code
Yes you can refer to table columns using the index number (position) in the table, indexed from 0.
So to refer to the 2nd column you would write TableName{1}
If it's always the same columns that have different names, what I would do is to load the table into Power Query then rename those columns to something standard that you can refer to in all subsequent steps.
For example, this code renames the 2nd and 3rd columns by referring to their position.
I don't know what your data looks like but it shouldn't be hard to modify this code to suit your data.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TY/LDcAgDEN34Vy55Adhlqr7r1FQScQpkp/s2M9T6KabK9dyFRbYPFTea+kcuihona1L6NThPq9uoAGagJeDN7AA6qh2gJYOho4jqmenAfOjlGdUw+ADjAC9QfSoSzWzHLq+W5Bc7v/ytOR08z9sWt4P", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Amount = _t, #"Customer ID" = _t]), RenameFirstCol = Table.RenameColumns(Source, {Table.ColumnNames(Source){1}, "Col2"}), RenameSecondCol = Table.RenameColumns(RenameFirstCol, {Table.ColumnNames(RenameFirstCol){2}, "Col3"}) in RenameSecondColRegards
Phil
Hi deanbland
Download sample PBIX with code
Yes you can refer to table columns using the index number (position) in the table, indexed from 0.
So to refer to the 2nd column you would write TableName{1}
If it's always the same columns that have different names, what I would do is to load the table into Power Query then rename those columns to something standard that you can refer to in all subsequent steps.
For example, this code renames the 2nd and 3rd columns by referring to their position.
I don't know what your data looks like but it shouldn't be hard to modify this code to suit your data.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TY/LDcAgDEN34Vy55Adhlqr7r1FQScQpkp/s2M9T6KabK9dyFRbYPFTea+kcuihona1L6NThPq9uoAGagJeDN7AA6qh2gJYOho4jqmenAfOjlGdUw+ADjAC9QfSoSzWzHLq+W5Bc7v/ytOR08z9sWt4P", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Amount = _t, #"Customer ID" = _t]),
RenameFirstCol = Table.RenameColumns(Source, {Table.ColumnNames(Source){1}, "Col2"}),
RenameSecondCol = Table.RenameColumns(RenameFirstCol, {Table.ColumnNames(RenameFirstCol){2}, "Col3"})
in
RenameSecondCol
Regards
Phil
Thank you Phil, works a treat!