Forum Discussion

ZBO125's avatar
ZBO125
Frequent Visitor
2 years ago
Solved

Create a function to get value from other column by condition

Hello, i'm new in PBI and trying to create column by comparing values from other column. id maincode values id code newcolumn 123456 1 aaa       123456 2 bbb       123...
  • ManuelBolz's avatar
    ManuelBolz
    2 years ago

    Okay ZBO125,

     

    i thing i get it:

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("zc65DYAwDIXhVVDqFCQkBGaJKHIf+w/Ag4JDcg/Fb8n6XNhaJuSk9Mw4E8g5hzmcbfyBEnnvaZxQCIFGhWKMNGqUUqLxKOdMo0GlFBoXVGulcUWtNRrFiNF7f6lZ1mvn9+3vUH/z0LYD", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [id = _t, maincode = _t, values = _t, id.1 = _t, code = _t]),
        Datatype = Table.TransformColumnTypes(Source,{{"id", Int64.Type}, {"maincode", Int64.Type}, {"values", type text}, {"id.1", Int64.Type}, {"code", Int64.Type}, {"newcolumn", type text}}),
        tblMainCode = Source[[maincode], [values]],
        Type = Table.TransformColumnTypes(tblMainCode,{{"maincode", Int64.Type}}),
        Distinct = Table.Distinct(Type, {"maincode"}),
        Join = Table.NestedJoin(Datatype, {"code"}, Distinct, {"maincode"}, "Tabelle3", JoinKind.LeftOuter),
        Expand = Table.ExpandTableColumn(Join, "Tabelle3", {"values"}, {"newvolumn"})
    in
        Expand

     

    Best regards from Germany

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