Forum Discussion

rmeng's avatar
rmeng
Icon for Helper II rankHelper II
5 years ago
Solved

Add a column with a list of Values

Can you help me with power query to add a column with a list of values into a table:

 

 

  • Hello rmeng 

     

    you can add a list as a formula for your new column. Afterwards expand the list to new rows. Here an example of a list for your new column (you can also reference a column of another query here like MyOtherQuery[List]

    {"Name", "etc"}

     here the complete code

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXJUitWJVjICspzALGMgy1kpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Name = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Name", type text}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each {"Name", "etc"}),
        #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom")
    in
        #"Expanded Custom"

    it transforms this

     

    into this

     

    Copy paste this code to the advanced editor in a new blank query to see how the solution works.

    If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
    Kudoes are nice too

    Have fun

    Jimmy

3 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Icon for Community Champion rankCommunity Champion

    rmeng Use a Merge query in Power Query Editor and I believe it looks like you want a Full Outer Join.

     

    • rmeng's avatar
      rmeng
      Icon for Helper II rankHelper II

      But I don´t have any comun ID between the List and the other table?

  • Jimmy801's avatar
    Jimmy801
    Icon for Community Champion rankCommunity Champion

    Hello rmeng 

     

    you can add a list as a formula for your new column. Afterwards expand the list to new rows. Here an example of a list for your new column (you can also reference a column of another query here like MyOtherQuery[List]

    {"Name", "etc"}

     here the complete code

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXJUitWJVjICspzALGMgy1kpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Name = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Name", type text}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each {"Name", "etc"}),
        #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom")
    in
        #"Expanded Custom"

    it transforms this

     

    into this

     

    Copy paste this code to the advanced editor in a new blank query to see how the solution works.

    If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
    Kudoes are nice too

    Have fun

    Jimmy