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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
kevinEGE
Regular Visitor

Expand column M

Good afternoon,

 

Im requesting sucefully an API with pbi. This api give me 2 fields "id" and "fields". fields its an column in aech row a list, and the list contain 3 records and each record have 2 rows, like this:

kevinEGE_1-1717085292194.png

kevinEGE_2-1717085366191.png

kevinEGE_3-1717085496259.png

kevinEGE_4-1717085519456.png

 

 

i want to have my final model like:

Columns> ID /  Quantidade / unidade / data e hora.

 

Anyone can help with M code? i really appreciate!! thank u so much!

 

 

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@kevinEGE I have created sample data and added the steps on how you can do it. Start a new query -> click advanced editor and paste the M code. Follow the same steps in your data.

 

let
  Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlSKjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1.id = _t]),
  #"Changed column type" = Table.TransformColumnTypes(Source, {{"Column1.id", type text}}, "en-US"),
  #"Added List with Records" = Table.AddColumn(#"Changed column type", "Column1.fields", each {[Rate=10, Qty=20],[Product = "A", Customer = "B"], [Country = "Canada", Province = "BC"]}),
  #"Added Position To List" = Table.AddColumn(#"Added List with Records", "ListPos", each List.Transform({0..List.Count([Column1.fields])-1}, (x as number) => Record.FromList({[Column1.fields]{x}, x}, {"Record", "Pos"}))),
  #"Removed Original List Column" = Table.RemoveColumns(#"Added Position To List", {"Column1.fields"}),
  #"Expanded List" = Table.ExpandListColumn(#"Removed Original List Column", "ListPos"),
  #"Expanded List Record and Pos" = Table.ExpandRecordColumn(#"Expanded List", "ListPos", {"Record", "Pos"}, {"Record", "Pos"}),
  #"Pivoted column" = Table.Pivot(Table.TransformColumnTypes(#"Expanded List Record and Pos", {{"Pos", type text}}), List.Distinct(Table.TransformColumnTypes(#"Expanded List Record and Pos", {{"Pos", type text}})[Pos]), "Pos", "Record"),
  #"Expanded 1st Record" = Table.ExpandRecordColumn(#"Pivoted column", "0", {"Rate", "Qty"}, {"Rate", "Qty"}),
  #"Expanded 2nd Record" = Table.ExpandRecordColumn(#"Expanded 1st Record", "1", {"Product", "Customer"}, {"Product", "Customer"}),
  #"Expanded 3rd Record" = Table.ExpandRecordColumn(#"Expanded 2nd Record", "2", {"Country", "Province"}, {"Country", "Province"})
in
  #"Expanded 3rd Record"


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

3 REPLIES 3
parry2k
Super User
Super User

@kevinEGE glad to hear it was helpful. Cheers!



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

kevinEGE
Regular Visitor

This was a perfect answer!!!

 

I've tried this rn and solved perfectly my problem.

 

thank you so much @parry2k !!

parry2k
Super User
Super User

@kevinEGE I have created sample data and added the steps on how you can do it. Start a new query -> click advanced editor and paste the M code. Follow the same steps in your data.

 

let
  Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlSKjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1.id = _t]),
  #"Changed column type" = Table.TransformColumnTypes(Source, {{"Column1.id", type text}}, "en-US"),
  #"Added List with Records" = Table.AddColumn(#"Changed column type", "Column1.fields", each {[Rate=10, Qty=20],[Product = "A", Customer = "B"], [Country = "Canada", Province = "BC"]}),
  #"Added Position To List" = Table.AddColumn(#"Added List with Records", "ListPos", each List.Transform({0..List.Count([Column1.fields])-1}, (x as number) => Record.FromList({[Column1.fields]{x}, x}, {"Record", "Pos"}))),
  #"Removed Original List Column" = Table.RemoveColumns(#"Added Position To List", {"Column1.fields"}),
  #"Expanded List" = Table.ExpandListColumn(#"Removed Original List Column", "ListPos"),
  #"Expanded List Record and Pos" = Table.ExpandRecordColumn(#"Expanded List", "ListPos", {"Record", "Pos"}, {"Record", "Pos"}),
  #"Pivoted column" = Table.Pivot(Table.TransformColumnTypes(#"Expanded List Record and Pos", {{"Pos", type text}}), List.Distinct(Table.TransformColumnTypes(#"Expanded List Record and Pos", {{"Pos", type text}})[Pos]), "Pos", "Record"),
  #"Expanded 1st Record" = Table.ExpandRecordColumn(#"Pivoted column", "0", {"Rate", "Qty"}, {"Rate", "Qty"}),
  #"Expanded 2nd Record" = Table.ExpandRecordColumn(#"Expanded 1st Record", "1", {"Product", "Customer"}, {"Product", "Customer"}),
  #"Expanded 3rd Record" = Table.ExpandRecordColumn(#"Expanded 2nd Record", "2", {"Country", "Province"}, {"Country", "Province"})
in
  #"Expanded 3rd Record"


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.