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! Learn more

Reply
rohitjmd
Helper II
Helper II

Stack data in power bi

hello, 

I am trying to stack data through data modeling. below is the scenerio. it wolud be greast help to me if anybody could suggest how to get the desired ouptut through Query/Dax. file attached https://1drv.ms/x/s!AqSgJWIdQo7TjDWaa1bYPYvHEBkq?e=h807Cx

image.png

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

Hi @rohitjmd ,

 

Choose the Respid and category column in power query and unpivot other columns. Then rename the columns to get the excepted result.

Capture.PNG2.PNG

 

M code for your reference.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fZG5EcMgEEV7IVbA3ktouwxG/bdhLsvAyJ5hIx7/WHIOlJjdOBzhUQbKSJnvOY8cgMUFfDD4g2E2ru+f1wUN+sMQgSr6wlQlnhg0dHJaGB1al1dSVqperyVHV8Kug8DoeMNIU2uMYAKJi5dteUAZOfLC+J5HySytOnvmsh4XpbFDmlym7okcCP8zZqB4111bt97ditVd996u5fGYVOPwiuPvJ6/zDQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Respid = _t, Category = _t, Q1 = _t, Q2 = _t, Q3 = _t, Q4 = _t, Q5 = _t, Q6 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Respid", Int64.Type}, {"Category", type text}, {"Q1", Int64.Type}, {"Q2", Int64.Type}, {"Q3", Int64.Type}, {"Q4", Int64.Type}, {"Q5", Int64.Type}, {"Q6", Int64.Type}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Category", "Respid"}, "Attribute", "Value"),
    #"Renamed Columns" = Table.RenameColumns(#"Unpivoted Other Columns",{{"Attribute", "Question"}, {"Value", "Answer"}})
in
    #"Renamed Columns"

 

 

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

3 REPLIES 3
v-frfei-msft
Community Support
Community Support

Hi @rohitjmd ,

 

Choose the Respid and category column in power query and unpivot other columns. Then rename the columns to get the excepted result.

Capture.PNG2.PNG

 

M code for your reference.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fZG5EcMgEEV7IVbA3ktouwxG/bdhLsvAyJ5hIx7/WHIOlJjdOBzhUQbKSJnvOY8cgMUFfDD4g2E2ru+f1wUN+sMQgSr6wlQlnhg0dHJaGB1al1dSVqperyVHV8Kug8DoeMNIU2uMYAKJi5dteUAZOfLC+J5HySytOnvmsh4XpbFDmlym7okcCP8zZqB4111bt97ditVd996u5fGYVOPwiuPvJ6/zDQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Respid = _t, Category = _t, Q1 = _t, Q2 = _t, Q3 = _t, Q4 = _t, Q5 = _t, Q6 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Respid", Int64.Type}, {"Category", type text}, {"Q1", Int64.Type}, {"Q2", Int64.Type}, {"Q3", Int64.Type}, {"Q4", Int64.Type}, {"Q5", Int64.Type}, {"Q6", Int64.Type}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Category", "Respid"}, "Attribute", "Value"),
    #"Renamed Columns" = Table.RenameColumns(#"Unpivoted Other Columns",{{"Attribute", "Question"}, {"Value", "Answer"}})
in
    #"Renamed Columns"

 

 

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

Thanks Guys

sturlaws
Resident Rockstar
Resident Rockstar

After you have imported the data into Power BI Desktop, click on "Edit queries" in the Home-ribbon.

 

Mark the columns Respid and Category:
p1.PNG

 

Go to transform-ribbon, and click on the small arrow next to "Unpivot columns":
p2.PNG

 

and select "unpivot other columns". Now rename columns appropriatly,

 

br,

S

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 Solution Authors