Add Multiple Columns in One Step - Power Query

Shreesurya

Board Regular
Joined
Jul 7, 2014
Messages
50
Hi,

How to add Three Custom Column in Powerquery with static Data in one step.

I don't want to create a new step every time I add the column.

Below is an example of a table I want to add. Please help me with this.

ABC
123
123
123
123
 
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="表1"]}[Content],
    res=Table.SplitColumn(
                            Table.AddColumn(
                                            Source,
                                            "n",
                                            each {1,2,3}
                                           ),
                            "n",
                            each _,
                            {"A","B","C"}
                         )
in
    res
1643384562858.png
 
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="表1"]}[Content],
    res=Table.TransformRows(
                            Source,
                            each _&[A=1,B=2,C=3]
                           )
in
    Table.FromRecords(res)
1643384699377.png
 
Upvote 0
Or faster.....

If you know the names of the columns you want to add and hold them in a list, you can easily add any number of extra columns. The below steps assume that you hold the column names that you want to add in a list called "myListName". Try something like this:-

Power Query:
#"Added Custom items from LIST" = Table.AddColumn(#"myPreviousStep", "Custom", each if Table.HasColumns(#"myPreviousStep",myListName) then #"myPreviousStep" else Table.Combine({#"myPreviousStep",Table.FromRows({},myListName)})),
    #"Expand list items" = #"Added Custom items from LIST"{0}[Custom],
    #"Replaced values in items from myListName" = Table.ReplaceValue(#"Expand list items",null,1,Replacer.ReplaceValue,myListName),
Hi! this works perfectly, is there any way to make the values of the columns added "null" instead of "1"?
 
Upvote 0

Forum statistics

Threads
1,223,671
Messages
6,173,737
Members
452,533
Latest member
Alex19k

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