Power Querry - adding multiple columns with values based on other query list.

Radoslaw Poprawski

Active Member
Joined
Jun 19, 2021
Messages
397
Office Version
  1. 365
Platform
  1. Windows
Hi all,
so basicly:
I have a specified column names as list (can be a table aswell if needed)
Now I need to add those names into my query and populate based on some values from this query.

so to add multiple columns in 1 step i usualy use syntax:
=
Power Query:
 Table.AddColumn( #"Added Custom", "Record", each [
Col1 =  "A",
Col2 = "B"
...Col99999 -"ZZZ"
])
However when i replace Col1 and Col2 with syntax like:

Power Query:
Table.ColumnNames(MyQuery){0}
That returns a text value im getting an error:

So how do I fix this error?
Or how can add a columns from a list and populate it?
I would not want to to add 20 ,30 columns manualy, and this way it would be dynamic
1670835458105.png
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
maybe

Power Query:
Table.AddColumn( #"Added Custom", "Record", each Record.FromList({"A","B", ... "ZZZ"}, Table.ColumnNames(MyQuery)))

Where the list count of {"A","B", ... "ZZZ"} must equal the count of Table.ColumnNames(MyQuery)
 
Upvote 0

Forum statistics

Threads
1,215,098
Messages
6,123,082
Members
449,094
Latest member
mystic19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top