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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Nickda0123
New Member

Transform columns whose data type is "List"

I have a table with 100 columns

 

In which there are 40 columns (which data type is "list") need to be Transform by this code:

 

List.Transform(list_column_names_need_transform, (columnName) => Table.TransformColumns(Table, {{columnName, each Text.Combine(List.Transform(_, Text.From), ",")}})),

 

I want the result is 1 table with 60 columns without Transform and 40 columns after Transform.

 

The result I want to got is a table with 100 columns which didn't have any "list" data type column

 

I alse don't want to list every column I want to Transform in the code (Because if later the number of columns (which data type is "list") increases, I have to re-edit the code, which is very difficult.)

 

Here is an example of my table:

 

Nickda0123_0-1671592058865.png

 

 

Please help me with this issue, Thanks everyone

 

1 ACCEPTED SOLUTION
ppm1
Solution Sage
Solution Sage

Here's one way to do it in the query editor.  To see how it works, just create a blank query, open the Advanced Editor and replace the text there with the M code below.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUXJWitWJVnICslyUYmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Column3", each {"E", "F", "G"}),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Column4", each {"H", "I", "J"}),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "RecordColumn", each _),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom2",{"RecordColumn"}),
    #"Added Custom3" = Table.AddColumn(#"Removed Other Columns", "Custom", each let 
fieldnames = Record.FieldNames([RecordColumn]),
updatedlist = List.Transform(Record.ToList([RecordColumn]), each try Text.Combine(_, ",") otherwise _),
newrecord = Record.FromList(updatedlist, fieldnames)
in 
newrecord),
    #"Removed Other Columns1" = Table.SelectColumns(#"Added Custom3",{"Custom"}),
    #"Expanded Custom" = Table.ExpandRecordColumn(#"Removed Other Columns1", "Custom", {"Column1", "Column2", "Column3", "Column4"}, {"Column1", "Column2", "Column3", "Column4"})
in
    #"Expanded Custom"

 

ppm1_0-1671630904083.png

 

ppm1_1-1671630913186.png

 

Pat

 

Microsoft Employee

View solution in original post

3 REPLIES 3
ppm1
Solution Sage
Solution Sage

Here's one way to do it in the query editor.  To see how it works, just create a blank query, open the Advanced Editor and replace the text there with the M code below.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUXJWitWJVnICslyUYmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Column3", each {"E", "F", "G"}),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Column4", each {"H", "I", "J"}),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "RecordColumn", each _),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom2",{"RecordColumn"}),
    #"Added Custom3" = Table.AddColumn(#"Removed Other Columns", "Custom", each let 
fieldnames = Record.FieldNames([RecordColumn]),
updatedlist = List.Transform(Record.ToList([RecordColumn]), each try Text.Combine(_, ",") otherwise _),
newrecord = Record.FromList(updatedlist, fieldnames)
in 
newrecord),
    #"Removed Other Columns1" = Table.SelectColumns(#"Added Custom3",{"Custom"}),
    #"Expanded Custom" = Table.ExpandRecordColumn(#"Removed Other Columns1", "Custom", {"Column1", "Column2", "Column3", "Column4"}, {"Column1", "Column2", "Column3", "Column4"})
in
    #"Expanded Custom"

 

ppm1_0-1671630904083.png

 

ppm1_1-1671630913186.png

 

Pat

 

Microsoft Employee

Thank you very much, this is what I want to find!

JirkaZ
Solution Specialist
Solution Specialist

I guess you could try to wrap your transformation code in a "try" statement.
Error handling - Power Query | Microsoft Learn

Or even better - make the list transformation code a function and then pass the columns to it.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors