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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
BI-Beginner
New Member

Table transformation challenge

Hi, I am somewhat new to PowerBI. Only been using it for less than a year. I have a dataset in the format below (top). What is the best way to transform it to the format on the bottom? Appreciate all the suggestions! 

 

BIBeginner_1-1670370271324.png

 

 

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @BI-Beginner ;

As HotChilli said, I'll add specific steps:

1.unpivot columns.

vyalanwumsft_0-1670380167983.png

2.split column by "#".

vyalanwumsft_1-1670380181313.png

3.select two columns then pivot it.

vyalanwumsft_2-1670380261209.pngvyalanwumsft_3-1670380273445.png

4.delete Attribute.2 column and the final result:

vyalanwumsft_4-1670380315480.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjQ0MlbSUSpPSQSSKqYgZlERiGmmFKsTreRiYmYO5CWmpIHEQCpTU1NBTAul2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Item = _t, #"Supplier Name#1" = _t, #" Supplier Cost#1" = _t, #"Supplier Name#2" = _t, #" Supplier Cost#2" = _t]),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(Source, {"Item"}, "Attribute", "Value"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Columns", "Attribute", Splitter.SplitTextByDelimiter("#", QuoteStyle.Csv), {"Attribute.1", "Attribute.2"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Item", type text}, {"Attribute.1", type text}, {"Attribute.2", Int64.Type}}),
    #"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[Attribute.1]), "Attribute.1", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Pivoted Column",{"Attribute.2"})
in
    #"Removed Columns"


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-yalanwu-msft
Community Support
Community Support

Hi, @BI-Beginner ;

As HotChilli said, I'll add specific steps:

1.unpivot columns.

vyalanwumsft_0-1670380167983.png

2.split column by "#".

vyalanwumsft_1-1670380181313.png

3.select two columns then pivot it.

vyalanwumsft_2-1670380261209.pngvyalanwumsft_3-1670380273445.png

4.delete Attribute.2 column and the final result:

vyalanwumsft_4-1670380315480.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjQ0MlbSUSpPSQSSKqYgZlERiGmmFKsTreRiYmYO5CWmpIHEQCpTU1NBTAul2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Item = _t, #"Supplier Name#1" = _t, #" Supplier Cost#1" = _t, #"Supplier Name#2" = _t, #" Supplier Cost#2" = _t]),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(Source, {"Item"}, "Attribute", "Value"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Columns", "Attribute", Splitter.SplitTextByDelimiter("#", QuoteStyle.Csv), {"Attribute.1", "Attribute.2"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Item", type text}, {"Attribute.1", type text}, {"Attribute.2", Int64.Type}}),
    #"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[Attribute.1]), "Attribute.1", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Pivoted Column",{"Attribute.2"})
in
    #"Removed Columns"


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi Yalan, 

 

Thanks for the suggestion! I ran into an issue at the last step. Can you please let me know what I might be doing wrong? 

I got the data set cleaned up and made it into the follow format. 

BIBeginner_0-1670435195582.png

When I tried to pivot the two columns, it gave me this error. 

BIBeginner_1-1670435274774.png

 

let
    Source = Excel.Workbook(File.Contents("C:\Users\test\Documents\Test Power BI\Book1.xlsx"), null, true),
    Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Item", type text}, {"Supplier #1", type text}, {"Supplier #1 Pricing", Int64.Type}, {"Supplier #2", type text}, {"Supplier #2 Pricing", Int64.Type}, {"Supplier #3", type text}, {"Supplier #3 Pricing", Int64.Type}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Item"}, "Attribute", "Value"),
    #"Replaced Value" = Table.ReplaceValue(#"Unpivoted Columns","#1","",Replacer.ReplaceText,{"Attribute"}),
    #"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","#2","",Replacer.ReplaceText,{"Attribute"}),
    #"Replaced Value2" = Table.ReplaceValue(#"Replaced Value1","#3","",Replacer.ReplaceText,{"Attribute"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Replaced Value2",{{"Value", type text}}),
    #"Pivoted Column" = Table.Pivot(#"Changed Type1", List.Distinct(#"Changed Type1"[Attribute]), "Attribute", "Value")
in
    #"Pivoted Column"

I figured it out... Because I didn't have an index column. Thank you for your help! 

HotChilli
Community Champion
Community Champion

Unpivot all columns except item.

Split the column with the numbers and then Pivot the column with Supplier Name and Supplier Cost in it.

There are plenty of examples of this in this PQ forum

Helpful resources

Announcements
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.