Forum Discussion

Fab117's avatar
Fab117
Icon for Helper IV rankHelper IV
3 years ago
Solved

[Power BI] Copy a column content from one table to another one (linked through common column)

Hello, I've 2 tables: Table 1 Code Quantity A 5 B 3 A 4 C 6 B 4 A 2 C 5 A 3 B 1 C 4   Table 2 Code Price A 1.00 $/unit B 1.20 $/un...
  • AlB's avatar
    3 years ago

    Hi Fab117 

    This can be done easily in Power query with a merge. Place the following M code in a blank query to see the steps. See it all at work in the attached file.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTJVitWJVnICsozBLJCYCZjlDGSZwWVN4LJGcFlTuJgxXJ0hXBaoIxYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Code = _t, Quantity = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Code", type text}, {"Quantity", Int64.Type}}),
        #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Code"}, Table2, {"Code"}, "Table2", JoinKind.LeftOuter),
        #"Expanded Table2" = Table.ExpandTableColumn(#"Merged Queries", "Table2", {"Price"}, {"Price"})
    in
        #"Expanded Table2"

     

    Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

    Contact me privately for support with any larger-scale BI needs, tutoring, etc.