Gerard Duggan
Gerard Duggan

Reputation: 25

How can I add a specific list column to each table within a list of tables in Power Query?

In power query, I have a list of tables, each with 6 rows and 2 columns.

I have a separate list of 6 values (1-6). I would like to add that list column (values 1-6) to each table within my list of tables.

What is the most appropriate M code to use?

Picture of what I want to achieve

Thanks

I was trying some Table functions, but unsuccessful

Upvotes: 0

Views: 386

Answers (1)

horseyride
horseyride

Reputation: 21373

Is this what you want? Appends a column to each table within a list of tables

// sample data set up
let Source = #table({"Column1", "Column2"},{{"A","B"},{"C","D"},{"E","F"},{"G","H"},{"I","J"},{"K","L"}}),
ListofTables = List.Transform({1..5}, each Source),
NewListColumn = #table({"Column1"},{{"M"},{"N"},{"O"},{"P"},{"Q"},{"R"}}),

// Appends a column to each table within a list of tables:
AppendNewListColumn=List.Transform (ListofTables, each Table.FromColumns(Table.ToColumns(_) & Table.ToColumns(NewListColumn),Table.ColumnNames(_)& {"New"}))
in AppendNewListColumn

enter image description here

To put new column first before other columns

 AppendNewListColumn=List.Transform (ListofTables, each Table.FromColumns(Table.ToColumns(NewListColumn)&Table.ToColumns(_),{"New"}&Table.ColumnNames(_)))

Upvotes: 1

Related Questions