Forum Discussion
Alfinthehouse
2 years agoRegular Visitor
Merged Query Question
Hi I am trying to merge 2 tables, but in a way that it only matches once for each project. The tables below should explain what I'm after better Table 1: Project Item Cost Project 1 A ...
- 2 years ago
Different Approach:
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], Table1 = Table.TransformColumnTypes(Source,{{"Project", type text}, {"Item", type text}, {"Cost", Int64.Type}}), Source2 = Excel.CurrentWorkbook(){[Name="Table2"]}[Content], Table2 = Table.TransformColumnTypes(Source2,{{"Project", type text}, {"Budget", Int64.Type}}), Merge = Table.NestedJoin(Table1,"Project",Table2,"Project","Merged"), #"Expanded Merged" = Table.ExpandTableColumn(Merge, "Merged", {"Budget"}, {"Budget"}), #"Grouped Rows" = Table.Group(#"Expanded Merged", {"Project"}, { {"all", (t)=>Table.FromColumns( Table.ToColumns(Table.RemoveColumns(t,"Budget")) & {{t[Budget]{0}} & List.Repeat({null}, Table.RowCount(t)-1)}, {"Project","Item","Cost","Budget"}), type table [Project=nullable text, Item=nullable text, Cost=nullable number, Budget=nullable number]}}), #"Expanded all" = Table.ExpandTableColumn(#"Grouped Rows", "all", {"Item", "Cost", "Budget"}) in #"Expanded all"
Chewdata
Responsive Resident
2 years agoHello,
Can you share your merge code, because a simple left-outer join should do the trick.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCijKz0pNLlEwVNJRcgRiQwOlWB1UYSfsws6YwkbYDTHCbogRdkOMsRtijN0QYyRDYgE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Project = _t, Item = _t, Cost = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Project", type text}, {"Item", type text}, {"Cost", Int64.Type}}),
#"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Project"}, Table2, {"Project"}, "Table2", JoinKind.LeftOuter),
#"Expanded Table2" = Table.ExpandTableColumn(#"Merged Queries", "Table2", {"Budget"}, {"Budget"})
in
#"Expanded Table2"