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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
suparnababu8
Super User
Super User

Need help on Pivot/Unpivot/Transpose in Power Query Editor

Hi @fabric_Community 

 

I need a help from all of you.

I have data like below mentioned image-1

 

suparnababu8_0-1704731489633.png

YearJanFEBMAR
2021ABCDEFGHIABCDEFGHIABCDEFGHI
L&T555555555
ETA444444444
CAT333333333
KBR222222222
Caterpillar111111111
D&G555555555
YearJanFEBMAR
2022ABCDEFGHIABCDEFGHIABCDEFGHI
L&T555555555
ETA444444444
CAT333333333
KBR222222222
Caterpillar111111111
D&G555555555
YearJanFEBMAR
2023ABCDEFGHIABCDEFGHIABCDEFGHI
L&T555555555
ETA444444444
CAT333333333
KBR222222222
Caterpillar111111111
D&G555555555

Image-1


I need out put like below mentioned image-2

 

suparnababu8_1-1704731533051.jpeg

Image-2

How can I achieve this requirement with the help of Power Query Editor.

 

Here I'm attaching table for your ready reference. 

Thanks in advance..!

 

Fowmy

Greg_Deckler

1 ACCEPTED SOLUTION
spinfuzer
Solution Sage
Solution Sage

 

Import Table into Power Query with no headers (headers should be Column1 to ColumnN).  

 

I did the replace value blanks to nulls because my data was blank instead of null.  You may not need to do that.

 

Copy and paste the entire code into a blank query to see example.

 

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WikxNLFLSUfJKzAOSEOTm6gRn+zoGQdmxOtFKRgZGhkC2o5MzkHRxdQOS7h6eRImAtPvElBoYGJmFAIVMCWKQBtcQRyDbhCAGqXV2BJlrTBCD1Ho7gXxlRBCDzU0sSS0qyMzJAYeTIUEM0uMC8ag70R4lNRaMRmNhEMSC8WgsUDsWYgE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t, Column7 = _t, Column8 = _t, Column9 = _t, Column10 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type","",null,Replacer.ReplaceValue,{"Column2", "Column3", "Column4", "Column5", "Column6", "Column7", "Column8", "Column9", "Column10"}),
    #"Grouped Rows" = Table.Group(#"Replaced Value", {"Column1"}, 
        {
            {"Rows", 
            each let
                tranpose_filldown = Table.FillDown(Table.Transpose(_),{"Column1"}),
                merge_cols = Table.PromoteHeaders(Table.Transpose(Table.CombineColumns(tranpose_filldown,{"Column1","Column2"},Combiner.CombineTextByDelimiter(";"),"Merged"))),
                unpivot = Table.UnpivotOtherColumns(merge_cols, {Table.ColumnNames(merge_cols){0}}, "Attribute", "Value"),
                year = Text.AfterDelimiter(Table.ColumnNames(unpivot){0},";"),
                add_year = Table.AddColumn(unpivot, "Year", each year),
                split = Table.SplitColumn(add_year,"Attribute",Splitter.SplitTextByDelimiter(";")),
                rename = Table.RenameColumns(
                    split,
                    {
                        {Table.ColumnNames(split){0}, "Column1"}
                    }
                )
            in
                rename
            }
        }, 
        GroupKind.Local, 
        (s,c) => Byte.From(c[Column1] = "Year")
        ),
    Combine = Table.Combine(#"Grouped Rows"[Rows])
in
    Combine

 

 

 

 

View solution in original post

2 REPLIES 2
suparnababu8
Super User
Super User

Thanks a lot. It worked for me.

spinfuzer
Solution Sage
Solution Sage

 

Import Table into Power Query with no headers (headers should be Column1 to ColumnN).  

 

I did the replace value blanks to nulls because my data was blank instead of null.  You may not need to do that.

 

Copy and paste the entire code into a blank query to see example.

 

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WikxNLFLSUfJKzAOSEOTm6gRn+zoGQdmxOtFKRgZGhkC2o5MzkHRxdQOS7h6eRImAtPvElBoYGJmFAIVMCWKQBtcQRyDbhCAGqXV2BJlrTBCD1Ho7gXxlRBCDzU0sSS0qyMzJAYeTIUEM0uMC8ag70R4lNRaMRmNhEMSC8WgsUDsWYgE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t, Column7 = _t, Column8 = _t, Column9 = _t, Column10 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type","",null,Replacer.ReplaceValue,{"Column2", "Column3", "Column4", "Column5", "Column6", "Column7", "Column8", "Column9", "Column10"}),
    #"Grouped Rows" = Table.Group(#"Replaced Value", {"Column1"}, 
        {
            {"Rows", 
            each let
                tranpose_filldown = Table.FillDown(Table.Transpose(_),{"Column1"}),
                merge_cols = Table.PromoteHeaders(Table.Transpose(Table.CombineColumns(tranpose_filldown,{"Column1","Column2"},Combiner.CombineTextByDelimiter(";"),"Merged"))),
                unpivot = Table.UnpivotOtherColumns(merge_cols, {Table.ColumnNames(merge_cols){0}}, "Attribute", "Value"),
                year = Text.AfterDelimiter(Table.ColumnNames(unpivot){0},";"),
                add_year = Table.AddColumn(unpivot, "Year", each year),
                split = Table.SplitColumn(add_year,"Attribute",Splitter.SplitTextByDelimiter(";")),
                rename = Table.RenameColumns(
                    split,
                    {
                        {Table.ColumnNames(split){0}, "Column1"}
                    }
                )
            in
                rename
            }
        }, 
        GroupKind.Local, 
        (s,c) => Byte.From(c[Column1] = "Year")
        ),
    Combine = Table.Combine(#"Grouped Rows"[Rows])
in
    Combine

 

 

 

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.

Top Kudoed Authors