Forum Discussion
S0Fr33
6 years agoFrequent Visitor
Merge Tables Without Matching Data
From a Support Ticket system, due to limitations with API calls, I have multiple tables with the same column names but different data. The tables are separated by date ranges. I need to merge th...
S0Fr33
6 years agoFrequent Visitor
I'd like to append the tables together.
P.S. - I read your article on how to get your question answered quickly and am providing a link to 2 sample tables with anonymized data.
Jimmy801
6 years agoCommunity Champion
Hello S0Fr33
add a prefix to every column (example table name) and combine the tables afterwards. I've prepared a very basic code example where you see how this could work
let
SourceTableA = #table
(
{"COLA","COL2"},
{
{"a","c"}, {"b","d"}, {"e","f"}
}
),
SourceTableB = #table
(
{"COLA","COL2"},
{
{"a","c"}, {"b","d"}, {"e","f"}
}
),
NewColumnNamesTableA = List.Transform(Table.ColumnNames(SourceTableA),each "TableA"&_),
NewColumnNamesTableB = List.Transform(Table.ColumnNames(SourceTableB),each "TableB"&_),
RenameTableA = Table.RenameColumns(SourceTableA,List.Zip({Table.ColumnNames(SourceTableA), NewColumnNamesTableA})),
RenameTableB = Table.RenameColumns(SourceTableB,List.Zip({Table.ColumnNames(SourceTableB), NewColumnNamesTableB})),
Combine = Table.Combine({RenameTableA, RenameTableB})
in
CombineCopy paste this code to the advanced editor in a new blank query to see how the solution works. If this solution fits your need, copy and past a part of it and implement it in your query.
If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too
Have fun
Jimmy