Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Merge Error: entire second query source is coming through; not the second query result

I have two queries "firstQuery" and "secondQuery"; they are both loaded to Connection Only. When I merge queries as new and then expand the table of the secondQuery, the entire source of secondQuery comes through instead of the final result of secondQuery. See example below.

 

firstQuery (result; after operations on the source):

firstQuery_column_1firstQuery_column_2
abc123

 

secondQuery (source):

secondQuery_column_1secondQuery_column_2
abc789
def012

 

secondQuery (result; after operations on the source):

secondQuery_column_1secondQuery_column_2
abc789

 

 

Here's the problem:

When I merge as new (firstQuery and secondQuery) with Full Outer Join and firstQuery_column_1 = secondQuery_column_2 and then expand the "Table" of the merged secondQuery, the entire secondQuery(source) comes through instead of the secondQuery(result). However, when I select each row of the "Table" prior to expanding, it shows exactly the one value that I want from secondQuery(result).

firstQuery_column_1firstQuery_column_2secondQuery_column_1secondQuery_column_2
abc123abc789
  def012

 

I expected the secondQuery(result) to be merged, not the secondQuery(source). This is what I expected:

firstQuery_column_1firstQuery_column_2secondQuery_column_1secondQuery_column_2
abc123abc789

 

I understand left, right, full, inner, outer and anti joins. The example above could have been resolved with an inner join. However, my real application requires the full join.

 

Why/how is the secondQuery(source) even available for merging in this situation when I am only selecting the secondQuery(result)???

  • Hello Anonymous 

     

    I can't reproduce your problem.  Maybe in your code is something wrong.  Maybe you can post here the m-code of your three queries.

    Here the secenario where I tied to reproduce it

    let
        Table1 = 
        let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSkxKVtJRMjQyVoqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [firstQuery_column_1 = _t, firstQuery_column_2 = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"firstQuery_column_1", type text}, {"firstQuery_column_2", Int64.Type}})
    in
        #"Changed Type",
        Table2 = let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSkxKVtJRMrewVIrViVZKSU0D8gwMjZRiYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [secondQuery_column_1 = _t, secondQuery_column_2 = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"secondQuery_column_1", type text}, {"secondQuery_column_2", Int64.Type}}),
        #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([secondQuery_column_1] = "abc"))
    in
        #"Filtered Rows",
    
    
        Join= Table.NestedJoin
        (
            Table1,
            "firstQuery_column_1", 
            Table2,
            "secondQuery_column_1",
            "Table2",
            JoinKind.FullOuter
        ),
        #"Expanded Table2" = Table.ExpandTableColumn(Join, "Table2", {"secondQuery_column_1", "secondQuery_column_2"}, {"secondQuery_column_1", "secondQuery_column_2"})
    in
        #"Expanded Table2"

     

    Copy paste this code to the advanced editor in a new blank query to see how the solution works.

    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

2 Replies

  • Jimmy801's avatar
    Jimmy801
    Community Champion

    Hello Anonymous 

     

    I can't reproduce your problem.  Maybe in your code is something wrong.  Maybe you can post here the m-code of your three queries.

    Here the secenario where I tied to reproduce it

    let
        Table1 = 
        let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSkxKVtJRMjQyVoqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [firstQuery_column_1 = _t, firstQuery_column_2 = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"firstQuery_column_1", type text}, {"firstQuery_column_2", Int64.Type}})
    in
        #"Changed Type",
        Table2 = let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSkxKVtJRMrewVIrViVZKSU0D8gwMjZRiYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [secondQuery_column_1 = _t, secondQuery_column_2 = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"secondQuery_column_1", type text}, {"secondQuery_column_2", Int64.Type}}),
        #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([secondQuery_column_1] = "abc"))
    in
        #"Filtered Rows",
    
    
        Join= Table.NestedJoin
        (
            Table1,
            "firstQuery_column_1", 
            Table2,
            "secondQuery_column_1",
            "Table2",
            JoinKind.FullOuter
        ),
        #"Expanded Table2" = Table.ExpandTableColumn(Join, "Table2", {"secondQuery_column_1", "secondQuery_column_2"}, {"secondQuery_column_1", "secondQuery_column_2"})
    in
        #"Expanded Table2"

     

    Copy paste this code to the advanced editor in a new blank query to see how the solution works.

    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

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you Jimmy, very helpful. As I was making up a test file to attach to this thread I also was not able to reproduce it. So then I went back to my actual dataset, started the query over and voila. Isn't that the way it goes sometime?! Thank you 1000x for your detailed reply!