Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

LOOKUP with different columns in the same excel sheet

Hi,   I am new to power BI. I am trying to do lookup function for the below scenario.   File - 1 Column 1 - Product Category (Which has codes, blanks, #) Column 2 - Big C   File - 2 Column 1...
  • dax's avatar
    dax
    6 years ago

    Hi Vaishu0508,

    You could try to unpivot table 2, then merge table 1 and table two, you could refer to below M code 

    Table 1

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnYzNjAwUNJRUorVAfEMjQ1NkXlG5giegYERgmOKrMvMEMKJBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"PCAT " = _t, #"Big C" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"PCAT ", type text}, {"Big C", type text}}),
        #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"PCAT "}, t2, {"Value"}, "t2", JoinKind.LeftOuter),
        #"Expanded t2" = Table.ExpandTableColumn(#"Merged Queries", "t2", {"Big C"}, {"t2.Big C"}),
        #"Removed Columns" = Table.RemoveColumns(#"Expanded t2",{"Big C"})
    in
        #"Removed Columns"

    Table 2

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnYzNjAwUNIBMgyNDU2hDCNzIMMjPzdVwTmxKFUpVgek0ASqzsjAEEwbGBiBVLkpxcYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Division Code" = _t, #"Category Code" = _t, #"Market Code" = _t, #"Big C" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Division Code", type text}, {"Category Code", type text}, {"Market Code", type text}, {"Big C", type text}}),
        #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Big C"}, "Attribute", "Value")
    in
        #"Unpivoted Columns"

    Best Regards,
    Zoe Zhi

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.