Power Query - split out lines of data in a single cell

Frazzle

New Member
Joined
Nov 6, 2019
Messages
2
Hi, I have the following data in excel and am looking for a way to split it out into seperate lines - I was thinking Power Query could be the answer but not sure on the steps I could take. It is a one off data clean so I am also up for doing it in Excel via formula but again not certain on the steps to take. It's about 5000 lines of data.

Current Data:

WebsiteItemsPriceQuantity
EbayChair
Bed
Table
15
100
50
4
1
1
Madeup.comCarpet1002
AmazonLamp
Couch
20
100
4
1

<tbody>
</tbody>

What I would like:

WebsiteItemsPriceQuantity
EbayChair154
EbayBed1001
EbayTable501
Madeup.comCarpet1002
AmazonLamp204
AmazonCouch1001

<tbody>
</tbody>

Appreciate any help you could provide!
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Is Chair, Bed, Table all on different rows? If so, just right click the Website column and Fill dowm
 
Upvote 0
  1. duplicate table twice
  2. from the first remove Price and Quantity
  3. split Items by lf
  4. add Index
  5. from the second remove Items and Quantity
  6. split Price by lf
  7. add index
  8. from the third remove Items and Price
  9. split Quantity by lf
  10. add Index
  11. merge 1st table with table2 by Index
  12. expand
  13. merge merged table with table3 by index
  14. expand
  15. remove Index

I hope I didn't miss something

it can be done in single optimised Query

WebsiteItemsPriceQuantity
EbayChair
Bed
Table
15
100
50
4
1
1
Madeup.comCarpet
100​
2​
AmazonLamp
Couch
20
100
4
1
WebsiteItemsPriceQuantity
EbayChair154
EbayBed1001
EbayTable501
Madeup.comCarpet1002
AmazonLamp204
AmazonCouch1001
 
Last edited:
Upvote 0
Ah. If everything is in same cell, you can do this, no merging or indexing necessary

* Add custom columns that use Text.Split to create split lists for each column
* Create a table from those columns
* Expand
* Fill down

Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Website", type text}, {"Items", type text}, {"Price", type text}, {"Quantity", type text}}),
    #"Added Custom0" = Table.AddColumn(#"Changed Type",  "Custom1", each Text.Split([Website],"#(lf)")),
    #"Added Custom1" = Table.AddColumn(#"Added Custom0", "Custom2", each Text.Split([Items],"#(lf)")),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Custom3", each Text.Split([Price],"#(lf)")),
    #"Added Custom3" = Table.AddColumn(#"Added Custom2", "Custom4", each Text.Split([Quantity],"#(lf)")),
    #"Added Custom4" = Table.AddColumn(#"Added Custom3", "Custom5", each Table.FromColumns({[Custom1],[Custom2],[Custom3],[Custom4]})),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom4",{"Custom5"}),
    #"Expanded Custom5" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom5", {"Column1", "Column2", "Column3", "Column4"}, {"Website", "Items", "Price", "Quantity"}),
    #"Filled Down" = Table.FillDown(#"Expanded Custom5",{"Website"})
in #"Filled Down"
 
Upvote 0
Other way
Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Tabela1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Website", type text}, {"Items", type text}, {"Price", type text}, {"Quantity", type text}}),
    TableTransform = Table.Combine(List.Transform(List.Transform(Table.ToRecords(#"Changed Type"), (x) => List.Transform(Record.ToList(x), each Text.Split(_,"#(lf)"))), each Table.FromColumns(_, Table.ColumnNames(Source)))),
    #"Filled Down" = Table.FillDown(TableTransform,{"Website"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Filled Down",{{"Website", type text}, {"Items", type text}, {"Price", type number}, {"Quantity", Int64.Type}})
in
    #"Changed Type1"
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,022
Members
448,939
Latest member
Leon Leenders

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