Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Merge Queries: Columns with a true match AND a false match

Hello everyone,   I have two tables filled with two different kind of tasks (e.g. table X and Y), and some columns brings the start date and finish date. So, from the subtraction of dates I have th...
  • jennratten's avatar
    5 years ago

    Hello - this is how you could accomplish this...

     

    In this example, I have two tables: Table1 and Table2.  I would like create a new table (Table3) with records in which the Student ID and Student Name match, but Attribute/Subject do not.

     

    Table1:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXJ0cgaSrnnpOZnFGUBWZGqxUqxOtJIRkO3k7AIkg5MzU/OSU5HkjIFsZxdXIOmbWJJRjCRjAmS7uLphkTEF2eLmjtUuMyDbzd0DVZeCUmwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Student ID" = _t, #"Student Name" = _t, Attribute = _t, Exemption = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Student ID", Int64.Type}, {"Student Name", type text}, {"Attribute", type text}, {"Exemption", type text}})
    in
        #"Changed Type"

     

    Table2:

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXJ0cgaSrnnpOZnFGUCWhYFSrE60khGQ6eTsAiSDkzNT85JTgSwzU7CUMZDp7OIKJH0TSzKKgbQJRMIEyHRxdUOSgBpmCrLBzR3FHnOIlBmQ6ebuASQ9MotL8osqoVKxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Student ID" = _t, #"Student Name" = _t, Subject = _t, #"Marks " = _t]),
        ChangeType = Table.TransformColumnTypes(Source,{{"Student ID", Int64.Type}, {"Student Name", type text}, {"Subject", type text}, {"Marks ", Int64.Type}})
    in
        ChangeType

     

    Table3:

    let
        Source = Table2,
        Merge = Table.NestedJoin(Source, {"Student ID", "Student Name"}, Table1, {"Student ID", "Student Name"}, "ExemptionData", JoinKind.LeftOuter),
        FilterSubtables = Table.SelectRows ( Merge, each [Subject] <> [ExemptionData][Attribute]{0})
    in
        FilterSubtables