Forum Discussion

VRMENDESadq's avatar
VRMENDESadq
Frequent Visitor
1 year ago
Solved

Return all values ​​appearing in a given column

HI, I need to create a custom column that shows all the values ​​in the "Origem" column according to the value in the "Produto" column, for example:    Produto Origem Custom Colunm 1 A A,...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Firstly, I duplicated the Table and named it Table2.

     

    In Table, this is the M-Code to transform the column to the custom column that you want:

    = Table.Group(Source, {"Produto"}, {{"Custom Column", each Text.Combine([Origem], ";"), type text}})

    This is the result:

    Then I use merge function in PQ to add custom column to Table2 to get the final result.

     

  • Ahmedx's avatar
    Ahmedx
    1 year ago

    pls try again

    let
    
    
    lst = List.Buffer( Table.ToList( from,(x)=>x)),
    f= (w)=>  Text.Combine( List.Transform(List.PositionOf( List.Transform(lst,(z)=>z{0}),w,Occurrence.All), (x)=> lst{x}{1}?),", "),
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXJUitWBsJzALCO4mBGKmDOYZQyXNYbLmkDEYgE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Produto = _t, Origem = _t]),
        from = Table.TransformColumnTypes(Source,{{"Produto", Int64.Type}, {"Origem", type text}}),
        #"Added Custom1" = Table.AddColumn(from, "Custom", each f([Produto]))
    in
        #"Added Custom1"