Forum Discussion

Vrykolakas's avatar
Vrykolakas
Frequent Visitor
3 years ago
Solved

Data Transformation challenge.. Replace values from another Table, with specific condition

Hello dear PBI Community, I'm struggling with the following transformation..    I have two Tables, The one on top contains the Values I'm trying to get onto the second Table ( column1, Gro...
  • v-yalanwu-msft's avatar
    3 years ago

    Hi, Vrykolakas ;

    Try it.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKkktLsnMS1fSUXICYkelWB1kMWcgRhMCq0QVcsQi5gLGmOqw2eCsFBsLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, #"Group 0" = _t, #"Group 1" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Group 0", type text}, {"Group 1", type text}}),
        Custom1 = let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKkktLsnMS1fSUXICYkelWB1kMWcgRhMCq0QVcsQi5gLGmOqw2eCsFBsLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, #"Group 0" = _t, #"Group 1" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Group 0", type text}, {"Group 1", type text}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each {List.Zip({#"Table1"[Group],#"Table1"[Number 0]}),List.Zip({#"Table1"[Group],#"Table1"[Number 1]})}
    ),
        #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each List.ReplaceMatchingItems({[Group 0]},[Custom]{0}){0}
    ),
        #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Custom.2", each List.ReplaceMatchingItems({[Group 1]},[Custom]{1}){0}
    )
    in
        #"Added Custom2",
        #"Removed Columns" = Table.RemoveColumns(Custom1,{"Group 0", "Group 1", "Custom"})
    in
        #"Removed Columns"

    The final show:


    Best Regards,
    Community Support Team _ Yalan Wu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.