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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
SteveW_Stats
Frequent Visitor

Convert table shape - remove columns and add as rows

Hi all

 

I'm new to PowerBI/Power Query and hope someone can help. I'm not sure what the technical term is for this process that I'm trying to achieve. I'll describe the start & end points as best I can:

My dataset looks like this:

 

NamePets
JimCat
BobDog,Cat,Hamster
PeteCat,Dog
TonyDog,Bird

 

I want a row for each person/animal pair. So far I've been able to split the animal column, by delimiter, in Power Query - which gives me this:

NamePets1Pets2Pets3
JimCat  
BobDogCatHamster
PeteCatDog 
TonyDogBird 

 

My end goal is for it to look like this:

 

NamePet
JimCat
BobDog
PeteCat
TonyDog
BobCat
PeteDog
TonyBird
BobHamster

 

I'd be most grateful for any guidance.

 

Thanks

2 ACCEPTED SOLUTIONS
smpa01
Community Champion
Community Champion

@SteveW_Stats  you can do this

let
    Source = Web.BrowserContents("https://community.fabric.microsoft.com/t5/Power-Query/Convert-table-shape-remove-columns-and-add-as-rows/m-p/3580119#M117343"),
    #"Extracted Table From Html" = Html.Table(Source, {{"Column1", "TABLE:nth-child(6) > * > TR > :nth-child(1)"}, {"Column2", "TABLE:nth-child(6) > * > TR > :nth-child(2)"}}, [RowSelector="TABLE:nth-child(6) > * > TR"]),
    #"Changed Type" = Table.TransformColumnTypes(#"Extracted Table From Html",{{"Column1", type text}, {"Column2", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.Split([Column2],",")),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Column2"}),
    #"Expanded Custom" = Table.ExpandListColumn(#"Removed Columns", "Custom")
in
    #"Expanded Custom"

========================
Did I answer your question? Mark my post as a solution!
Proud to be a Super User
My Custom Visualization Projects
• Plotting Live Sound: Live Sound
• Beautiful News: Women in Parliament, Energy Mix, Shrinking Armies
• Visual Capitalist: Working Hrs
• Others: Easing Graph, Animated Calendar
MayViz Submissions
• Week 1: View
• Week 2: View
• Week 3: View
• Week 4: View
========================

View solution in original post

slorin
Super User
Super User

4 REPLIES 4
slorin
Super User
Super User

Hi,

Look at "Advanced options" and choose Rows, not Columns
https://community.fabric.microsoft.com/t5/Power-Query/Reverse-pivots-with-multiple-columns-Transform...

 

Stéphane

Thanks very much, that was a lot easier to do.

smpa01
Community Champion
Community Champion

@SteveW_Stats  you can do this

let
    Source = Web.BrowserContents("https://community.fabric.microsoft.com/t5/Power-Query/Convert-table-shape-remove-columns-and-add-as-rows/m-p/3580119#M117343"),
    #"Extracted Table From Html" = Html.Table(Source, {{"Column1", "TABLE:nth-child(6) > * > TR > :nth-child(1)"}, {"Column2", "TABLE:nth-child(6) > * > TR > :nth-child(2)"}}, [RowSelector="TABLE:nth-child(6) > * > TR"]),
    #"Changed Type" = Table.TransformColumnTypes(#"Extracted Table From Html",{{"Column1", type text}, {"Column2", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.Split([Column2],",")),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Column2"}),
    #"Expanded Custom" = Table.ExpandListColumn(#"Removed Columns", "Custom")
in
    #"Expanded Custom"

========================
Did I answer your question? Mark my post as a solution!
Proud to be a Super User
My Custom Visualization Projects
• Plotting Live Sound: Live Sound
• Beautiful News: Women in Parliament, Energy Mix, Shrinking Armies
• Visual Capitalist: Working Hrs
• Others: Easing Graph, Animated Calendar
MayViz Submissions
• Week 1: View
• Week 2: View
• Week 3: View
• Week 4: View
========================

Thanks very much, that was incredibly fast.

I've modified your solution to suit as follows. It worked perfectly.

 

let
Source = PetData,
#"Changed Type" = Source,
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.Split([Pets],",")),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Pets"}),
#"Expanded Custom" = Table.ExpandListColumn(#"Removed Columns", "Custom")
in
#"Expanded Custom"

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.