Search code examples
excelpowerbipowerquerym

Power Query: How do I add a specific List/Vector as a Column


I have a simple problem. Let's assume I have the following

enter image description here

Now I want to add a specific vector or list for example (1,2,2,1) as an additional column and it should look like

enter image description here

When I add "Custom Column", how do I have to enter this list that it creates exactly this column? It should not be a index column or a calculated column because I want to specify the values depending on another column manually. It seems like it is a very simple task, but I couldn't find any solutions yet! (I feel very stupid xD)

pls help

Thank you!


Solution

  • let Source = #table({"Column1"},{{"A"},{"B"},{"C"},{"D"}}),
    Add = {{1,2,2,1}},
    part1=Table.ToColumns(Source) & Add,
    part2= Table.FromColumns(part1,Table.ColumnNames(Source)&{"Column2"})
    in part2
    

    or perhaps, if grabbing column from another table

    let Source = #table({"Column1"},{{"A"},{"B"},{"C"},{"D"}}),
    part1=Table.ToColumns(Source) & Table.ToColumns(Table.SelectColumns(SomeOtherTable,"Column9")),
    part2 = Table.FromColumns(part1,Table.ColumnNames(Source)&{"Column2"})
    in part2