Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hi everyone,
I'm having issues with merging two queries together.
My Table 1 looks like that:
ID | Data_1 | Data_2 | Date_Field |
ABC | 100 | 150 | 07/23/2024 |
ABC | 110 | 160 | 07/24/2024 |
ABC | 130 | N/A | 07/26/2024 |
After a bunch of PowerQuery steps, I keep only the latest value of the data to make it look like that :
ID | Data_1 | Data_2 |
ABC | 130 | 160 |
I use some filters, some conditional formulas and also a duplicate removal steps. So at the very last step of my query, I have only one version of each ID in the table, which the latest version of data, which is exactly what I want.
Now comes my second table, that has the same ID on its records, where I need to perform the merge to get the Data_1 and Data_2 fields.
For that I use the "Merge Query" Left Outer function and select both IDs in both table to perform the merge. I have exact matching and I would expect the Table 2 to look like that :
Other Data | ID | Table1.Data_1 | Table1.Data_2 |
XXXXX | ABC | 130 | 160 |
Turns out it does not at all and it keeps giving me wrong data from the Table1, like that :
Other Data | ID | Table1.Data_1 | Table1.Data_2 |
XXXXX | ABC | 100 | 150 |
I do not understand this behaviour as I would expect the merge to be performed on the latest step of the Table1 query, including the removal of old data. It looks like it is returning me some rows that are deleted in my Table1.
Any hints on how to solve this ?
Thanks a lot in avance!
Solved! Go to Solution.
Hi @EtienneT ,
Thanks for @PwerQueryKees reply.
Not sure about the structure of your second table based on your description, here's my test data
Table 2
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRyVtJRMjQwAJGmINLAXN/IWN/IwMhEKVYHrsAQrMAMpsAEQ4ExSMpP3xGqwAyqIBYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Data_1 = _t, Data_2 = _t, Date_Field = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"Data_1", Int64.Type}, {"Data_2", type text}, {"Date_Field", type date}}),
SortedTable = Table.Sort(Source,{{"ID", Order.Ascending}, {"Date_Field", Order.Descending}}),
AddIndex = Table.AddIndexColumn(SortedTable, "Index", 1, 1, Int64.Type),
GroupedTable = Table.Group(AddIndex, {"ID"}, {
{"LatestData", each
let
LatestData1 = List.First([Data_1]),
LatestData2 = if List.First([Data_2]) <> "N/A" then List.First([Data_2]) else List.First(List.Skip([Data_2], 1))
in
[Data_1 = LatestData1, Data_2 = LatestData2]
}
}),
ExpandedTable = Table.ExpandRecordColumn(GroupedTable, "LatestData", {"Data_1", "Data_2"}),
#"Merged Queries" = Table.NestedJoin(ExpandedTable, {"ID"}, #"Table (2)", {"ID"}, "Table (2)", JoinKind.LeftOuter),
#"Expanded Table (2)" = Table.ExpandTableColumn(#"Merged Queries", "Table (2)", {"Other data"}, {"Table (2).Other data"})
in
#"Expanded Table (2)"
Final output
Best regards,
Albert He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Hi @EtienneT ,
Thanks for @PwerQueryKees reply.
Not sure about the structure of your second table based on your description, here's my test data
Table 2
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRyVtJRMjQwAJGmINLAXN/IWN/IwMhEKVYHrsAQrMAMpsAEQ4ExSMpP3xGqwAyqIBYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Data_1 = _t, Data_2 = _t, Date_Field = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"Data_1", Int64.Type}, {"Data_2", type text}, {"Date_Field", type date}}),
SortedTable = Table.Sort(Source,{{"ID", Order.Ascending}, {"Date_Field", Order.Descending}}),
AddIndex = Table.AddIndexColumn(SortedTable, "Index", 1, 1, Int64.Type),
GroupedTable = Table.Group(AddIndex, {"ID"}, {
{"LatestData", each
let
LatestData1 = List.First([Data_1]),
LatestData2 = if List.First([Data_2]) <> "N/A" then List.First([Data_2]) else List.First(List.Skip([Data_2], 1))
in
[Data_1 = LatestData1, Data_2 = LatestData2]
}
}),
ExpandedTable = Table.ExpandRecordColumn(GroupedTable, "LatestData", {"Data_1", "Data_2"}),
#"Merged Queries" = Table.NestedJoin(ExpandedTable, {"ID"}, #"Table (2)", {"ID"}, "Table (2)", JoinKind.LeftOuter),
#"Expanded Table (2)" = Table.ExpandTableColumn(#"Merged Queries", "Table (2)", {"Other data"}, {"Table (2).Other data"})
in
#"Expanded Table (2)"
Final output
Best regards,
Albert He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
#"Merge Table1" = Table.NestedJoin(#"Previous step", {"ID"}, #"Name of the final result", {"ID"}, "Table 1", JoinKind.LeftOuter)
Hard to say without seeing your code.
Everything is in one Query? Then you should refer to the name of the step showing the final result you showed in your post.
You don't refer to the final query results.
Show your m code...
Hey, thanks for the answer
I cannot post the code here for privacy policy but it looks like that :
#"Merge Table1" = Table.NestedJoin(#"Previous step", {"ID"}, #"Table1", {"ID"}, "Table 1", JoinKind.LeftOuter)
How can I refer exactly to the final query result ?
Thanks
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
9 | |
6 | |
6 | |
6 | |
6 |
User | Count |
---|---|
9 | |
9 | |
8 | |
6 | |
6 |