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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Displaying some columns as rows and some as columns

Hello everyone,

 

I have value like this :

James_C_0-1652107973752.png

 

How can I display this data in a table visual with a slicer in which I select then zone, and then get something like this :

James_C_0-1652108065971.png

 

 

 

Any help appreciated !

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @Anonymous 

 

You can create a new table with below DAX. Replace 'Table' with your original table name. 

New Table = 
VAR _tableQuestion1 = SELECTCOLUMNS('Table',"Zone",'Table'[Zone],"Questions",'Table'[Question1],"Answers",'Table'[Answer Question1])
VAR _tableQuestion2 = SELECTCOLUMNS('Table',"Zone",'Table'[Zone],"Questions",'Table'[Question2],"Answers",'Table'[Answer Question2])
VAR _tableQuestion3 = SELECTCOLUMNS('Table',"Zone",'Table'[Zone],"Questions",'Table'[Question3],"Answers",'Table'[Answer Question3])
RETURN
UNION(_tableQuestion1,_tableQuestion2,_tableQuestion3)

vjingzhang_2-1652343581171.png

 

Then use columns from this new table in the Zone slicer and the table visual. 

vjingzhang_1-1652343468043.png

Hope it helps. 

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

4 REPLIES 4
v-jingzhang
Community Support
Community Support

Hi @Anonymous 

 

You can create a new table with below DAX. Replace 'Table' with your original table name. 

New Table = 
VAR _tableQuestion1 = SELECTCOLUMNS('Table',"Zone",'Table'[Zone],"Questions",'Table'[Question1],"Answers",'Table'[Answer Question1])
VAR _tableQuestion2 = SELECTCOLUMNS('Table',"Zone",'Table'[Zone],"Questions",'Table'[Question2],"Answers",'Table'[Answer Question2])
VAR _tableQuestion3 = SELECTCOLUMNS('Table',"Zone",'Table'[Zone],"Questions",'Table'[Question3],"Answers",'Table'[Answer Question3])
RETURN
UNION(_tableQuestion1,_tableQuestion2,_tableQuestion3)

vjingzhang_2-1652343581171.png

 

Then use columns from this new table in the Zone slicer and the table visual. 

vjingzhang_1-1652343468043.png

Hope it helps. 

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

rohit_singh
Solution Sage
Solution Sage

This can be done using power query. You will first need to perform an unpivot transformation to reshape the data. Then get your data in the required format by using an index column and group by.

rohit_singh_0-1652109468312.png

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WijJU0lEKRMKOcByrA5Q2wi9tjF/aBL+0KX5pM/zS5vilLfBLW+KWjgUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, Q1 = _t, Q2 = _t, Q3 = _t, A1 = _t, A2 = _t, A3 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"(blank)", type text}, {"Q1", type text}, {"Q2", type text}, {"Q3", type text}, {"A1", type text}, {"A2", type text}, {"A3", type text}}),
#"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"(blank)"}, "Attribute", "Value"),
#"Merged Columns" = Table.CombineColumns(#"Unpivoted Columns",{"Attribute", "Value"},Combiner.CombineTextByDelimiter(" - ", QuoteStyle.None),"Merged"),
#"Added Conditional Column" = Table.AddColumn(#"Merged Columns", "Index", each if Text.Contains([Merged], "1") then 1 else if Text.Contains([Merged], "2") then 2 else if Text.Contains([Merged], "3") then 3 else 0),
#"Merged Columns1" = Table.CombineColumns(Table.TransformColumnTypes(#"Added Conditional Column", {{"Index", type text}}, "en-GB"),{"(blank)", "Index"},Combiner.CombineTextByDelimiter(" - ", QuoteStyle.None),"Merged.1"),
#"Grouped Rows" = Table.Group(#"Merged Columns1", {"Merged.1"}, {{"Count", each _, type table [#"(blank)"=nullable text, Attribute=text, Value=text]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each [Count][Merged]),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Count"}),
#"Extracted Values" = Table.TransformColumns(#"Removed Columns", {"Custom", each Text.Combine(List.Transform(_, Text.From), " , "), type text}),
#"Extracted Text Before Delimiter" = Table.TransformColumns(#"Extracted Values", {{"Merged.1", each Text.BeforeDelimiter(_, " -"), type text}}),
#"Renamed Columns" = Table.RenameColumns(#"Extracted Text Before Delimiter",{{"Merged.1", "Z"}})
in
#"Renamed Columns"

Anonymous
Not applicable

Could you redirect me to a tutorial or explain step by step ? I haven't ever pivotted a table.

And by the way, the source table cannot be altered itself as is it used in another visuals. Maybe we can simply make a copy of it and work from there ?

amitchandak
Super User
Super User

@Anonymous , First on all Unpivot all question and answer column in power query, Then use split by non digit and digit

 

then pivot the column that has non numeric values and values column from first unpivot

 

https://radacad.com/pivot-and-unpivot-with-power-bi

Split Column By Digit to Non Digit & Non Digit to Digit: https://youtu.be/tY4Yk1crS9s

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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