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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Marcel1989
Frequent Visitor

Transform table

Hello,

 

I have the following table:

 

AreaYearQuarterCat1Cat2Cat3
a120221111
a120232321
a220224245

 

I want to transform it to the following:

CategoryValueAreaYearQuarter
Cat11a120221
Cat13a120232
Cat12a220224
Cat21a120221
Cat22a120232
Cat24a220224
Cat31a120221
Cat31a120232
Cat35a220224

 

So basically transpose column Cat1, Cat2, Cat3 from table1 and create a separated line for each combination of Area, Year.

 

How can I do it? Thanks a lot, I am trying this for hours now.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Marcel1989 

Select three columns(cat1,cat2, cat3) together and the unpivot to get the desired result.
Also, PFB the M code (Advance Editor) 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSjRU0lEyMjAyAlKGKDhWByFrDKKAGEZDZY0Qek2gMiDaVCk2FgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Area = _t, Year = _t, Quarter = _t, Cat1 = _t, Cat2 = _t, Cat3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Area", type text}, {"Year", Int64.Type}, {"Quarter", Int64.Type}, {"Cat1", Int64.Type}, {"Cat2", Int64.Type}, {"Cat3", Int64.Type}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Area", "Year", "Quarter"}, "Attribute", "Value"),
    #"Reordered Columns" = Table.ReorderColumns(#"Unpivoted Columns",{"Attribute", "Value", "Area", "Year", "Quarter"}),
    #"Sorted Rows" = Table.Sort(#"Reordered Columns",{{"Attribute", Order.Ascending}})
in
    #"Sorted Rows"

pranit828_0-1675878449581.png

 

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Marcel1989 

Select three columns(cat1,cat2, cat3) together and the unpivot to get the desired result.
Also, PFB the M code (Advance Editor) 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSjRU0lEyMjAyAlKGKDhWByFrDKKAGEZDZY0Qek2gMiDaVCk2FgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Area = _t, Year = _t, Quarter = _t, Cat1 = _t, Cat2 = _t, Cat3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Area", type text}, {"Year", Int64.Type}, {"Quarter", Int64.Type}, {"Cat1", Int64.Type}, {"Cat2", Int64.Type}, {"Cat3", Int64.Type}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Area", "Year", "Quarter"}, "Attribute", "Value"),
    #"Reordered Columns" = Table.ReorderColumns(#"Unpivoted Columns",{"Attribute", "Value", "Area", "Year", "Quarter"}),
    #"Sorted Rows" = Table.Sort(#"Reordered Columns",{{"Attribute", Order.Ascending}})
in
    #"Sorted Rows"

pranit828_0-1675878449581.png

 

 

Hi @Anonymous 

 

thank you, your solution works perfectly. I think my understanding of unipivot was wrong, but I thanks to your answer I fully understand now.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.