cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
afernando Regular Visitor
Regular Visitor

Transform rows into columns

Hi,

 

I'm hoping someone can help me get addresses spread over a few rows into one row. The first table below is my input table and the second table is what I'd like to have as the output. 

 

input.PNGoutput.PNG

 

Any thoughts?

1 ACCEPTED SOLUTION

Accepted Solutions
afernando Regular Visitor
Regular Visitor

Re: Transform rows into columns

Thanks everyone. I figured it out myself. 

 

let
    Source = vendors,
    Partition = Table.Group(Source, {"Account No"}, {{"Partition", each Table.AddIndexColumn(_, "Index",1,1), type table}}),
    #"Expanded Partition" = Table.ExpandTableColumn(Partition, "Partition", {"Supplier Address", "Index"}, {"Partition.Supplier Address", "Partition.Index"}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Expanded Partition", {{"Partition.Index", type text}}, "en-AU"), List.Distinct(Table.TransformColumnTypes(#"Expanded Partition", {{"Partition.Index", type text}}, "en-AU")[Partition.Index]), "Partition.Index", "Partition.Supplier Address")
in
    #"Pivoted Column"

Cheers

View solution in original post

7 REPLIES 7
Super User
Super User

Re: Transform rows into columns

not sure but try this, select first column, right click and choose "pivot others"






Did I answer your question? Mark my post as a solution.

Proud to be a Datanaut! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.





stretcharm Senior Member
Senior Member

Re: Transform rows into columns

In Query editor pivot.

 

see some examples here

http://radacad.com/pivot-and-unpivot-with-power-bi

 

afernando Regular Visitor
Regular Visitor

Re: Transform rows into columns

Thanks everyone. I figured it out myself. 

 

let
    Source = vendors,
    Partition = Table.Group(Source, {"Account No"}, {{"Partition", each Table.AddIndexColumn(_, "Index",1,1), type table}}),
    #"Expanded Partition" = Table.ExpandTableColumn(Partition, "Partition", {"Supplier Address", "Index"}, {"Partition.Supplier Address", "Partition.Index"}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Expanded Partition", {{"Partition.Index", type text}}, "en-AU"), List.Distinct(Table.TransformColumnTypes(#"Expanded Partition", {{"Partition.Index", type text}}, "en-AU")[Partition.Index]), "Partition.Index", "Partition.Supplier Address")
in
    #"Pivoted Column"

Cheers

View solution in original post

Super User
Super User

Re: Transform rows into columns

very nice 






Did I answer your question? Mark my post as a solution.

Proud to be a Datanaut! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.





Ian-IKS Frequent Visitor
Frequent Visitor

Re: Transform rows into columns

Hi I tried this on my data which is similar but it puts all of the address information against the first row and creates over 8,000 columns. Any tips on what might be wrong. I copied your code

DAX0110 Member
Member

Re: Transform rows into columns

The second step should be a Fill Down.... revised code:

 

let
    Source = vendors,
FillDown = Table.FillDown(Source, {"Account No"}), Partition = Table.Group(FillDown, {"Account No"}, {{"Partition", each Table.AddIndexColumn(_, "Index",1,1), type table}}), #"Expanded Partition" = Table.ExpandTableColumn(Partition, "Partition", {"Supplier Address", "Index"}, {"Partition.Supplier Address", "Partition.Index"}), #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Expanded Partition", {{"Partition.Index", type text}}, "en-AU"), List.Distinct(Table.TransformColumnTypes(#"Expanded Partition", {{"Partition.Index", type text}}, "en-AU")[Partition.Index]), "Partition.Index", "Partition.Supplier Address") in #"Pivoted Column"

Highlighted
Ian-IKS Frequent Visitor
Frequent Visitor

Re: Transform rows into columns

That's great it works fine now Smiley Happy

Helpful resources

Announcements
Ask Amanda Anything Q&A

Ask Amanda Anything Q&A

Learn the answers to some of the questions asked during the Amanda Triple A event.

October 2019 Community Highlights

October 2019 Community Highlights

October was a busy month in the community. Read the recap article to learn about some of the events and content.

New Solution Badges

New Solution Badges

Two waves of brand new solution badges are coming! Read the article for more information on our new community badges.

Analytics in Azure virtual event

Analytics in Azure virtual event

Experience a limitless analytics service built to ingest, prep, manage, and serve data for immediate use in Power BI.

Users Online
Currently online: 128 members 1,404 guests
Please welcome our newest community members: