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

Columns to Rows Data Modelling Challenge

Hi - I think I'm close but stuck on final hurdle. I have used a combination of UnPivot, and Re-Pivot to get me there. 

 

I have a data set that looks like this (3 related fields for Product, Unit Price and Tax Code, three times):

Source_DataSet.png

I need to transform it to:

Target_DataSet.png

 

I've gotten this far, with Unpivot, and Pivot... but its not quite right. 

Close.png

Would really appreciate any assistance on the steps required to get the transform right (I had to add an Index column to overcome an error when I went to Pivot). I would prefer not to use DAX/M and only use whats available in the PBI Desktop interface. 

 

Thanks in Advance for any assistance. Original Sample Source Data in this link.

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Columns to Rows Data Modelling Challenge

@Gerard 

 

Attaching your Excel file as well. Please see the steps from Query Editor

 

 

View solution in original post

5 REPLIES 5
Super User
Super User

Re: Columns to Rows Data Modelling Challenge

Hi @Gerard 

 

Try this. It works with your sample data

 

let
    Source = Excel.CurrentWorkbook(){[Name="Original_DataSet"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"User Name", type text}, {"User ID", Int64.Type}, {"Product 1", type text}, {"Unit Price 1", type number}, {"Product 1 Tax Code", type text}, {"Product 2", type text}, {"Unit Price 2", type number}, {"Product 2 Tax Code", type text}, {"Product 3", type text}, {"Unit Price 3", type number}, {"Product 3 Tax Code", type text}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"User Name", "User ID"}, "Attribute", "Value"),
    #"Added Custom" = Table.AddColumn(#"Unpivoted Columns", "Custom", each Text.Select([Attribute],{"0".."9"})),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each Text.Remove([Attribute],{"0".."9"})),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Attribute"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[Custom.1]), "Custom.1", "Value")
in
    #"Pivoted Column"
Super User
Super User

Re: Columns to Rows Data Modelling Challenge

@Gerard 

 

Attaching your Excel file as well. Please see the steps from Query Editor

 

 

View solution in original post

Gerard Regular Visitor
Regular Visitor

Re: Columns to Rows Data Modelling Challenge

@Zubair_Muhammad  - thats very very clever - especially the first custom field.... thank you so much.  Would never have gotten that far on my own. 

 

QQ - Will there be any issues refreshing this dataset in Power BI?

 

Thanks,

Gerard

 

 

Super User
Super User

Re: Columns to Rows Data Modelling Challenge

@Gerard 

 

Hopefully no issues. But let me know if it gives error

Gerard Regular Visitor
Regular Visitor

Re: Columns to Rows Data Modelling Challenge

@Zubair_Muhammad  - Just to confirm, I have adapted this solution to my specific use case and it is working very well... there are also no issues with refreshes. 

 

Thank you so much for your help!

 

Regards

Gerard

 

Helpful resources

Announcements
Ask Amir Anything

Exclusive LIVE Community Event No. 2 – Ask Amir Anything

Next in our Triple A series: Ask Amir Netz questions about the latest updates, features and future.

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: 171 members 1,873 guests
Please welcome our newest community members: