Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Kthjelltësi
Frequent Visitor

Add more than one custom column in one step.

Hi

How could I add, let's say, 2 custom columns in one step. 
Thank you 😊 

4 REPLIES 4
dufoq3
Super User
Super User

Hi @Kthjelltësi, it is possible but why would you need that? It is better to create separate steps especially if you are still learning M code but as you wishL:

 

Result:

dufoq3_0-1709220325497.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKsovN1TSUTI0ABMGSrE6YDEjINfIAEzAxYyBXGMDMAEUiwUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Col1 = _t, Col2 = _t, Col3 = _t]),
    AddedColumns = Table.FromRecords(List.Transform(Table.ToRecords(Source), each _ & [ Col2_div = Number.From([Col2]) / 2, Col3_div = Number.From([Col3]) / 2 ]))
in
    AddedColumns

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Kthjelltësi
Frequent Visitor

Thank you for you reply.

I did not explain very well what I was after - sorry - so I'm going to have another go:

I have this table:

 

what i am doing is, add a custom column that divides Col2 by 2 then go back and add another custom column that divides Col3 by 2.

what i was wondering is "could this be done in a single step"?

thanks in advance.

Kthjelltsi_0-1708945651943.png

Use this where you will need to replace #"Changed Type" with your last step

= Table.FromRecords(List.Transform(Table.ToRecords(#"Changed Type"), (x)=> Record.Combine({x, [Custom1 = x[col2]/2, Custom2 = x[col3]/3]})))

Complete code

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WKsovN1TSUTI0ABMGSrE6YDEjINfIAEzAxYyBXGMDMAEUiwUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [col1 = _t, col2 = _t, col3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"col1", type text}, {"col2", Int64.Type}, {"col3", Int64.Type}}),
    Custom1 = Table.FromRecords(List.Transform(Table.ToRecords(#"Changed Type"), (x)=> Record.Combine({x, [Custom1 = x[col2]/2, Custom2 = x[col3]/3]})))
in
    Custom1

 

Vijay_A_Verma
Super User
Super User

There are many ways to do it but the best way would depend upon your particular business case. One way is below. We can do through List.Accumulate, Records etc as well. 
In this example, I am extracting First and Last Name

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCs7NLMlQ8MrPyFPSUTIxVYrViVZyzcksTlRwys8vyQAKmgEFYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Name = _t, Age = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Age", Int64.Type}}),
    Custom1 = Table.FromColumns(Table.ToColumns(#"Changed Type") & {List.Transform(#"Changed Type"[Name], each Text.Split(_," "){0}), List.Transform(#"Changed Type"[Name], each List.Last(Text.Split(_," ")))}, Table.ColumnNames(#"Changed Type") & {"First Name", "Last Name"})
in
    Custom1

 

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors