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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
lodwong
Regular Visitor

Multiple answer analysis

Screenshot.png

I need help in pivoting the about data set which came as a result of respondents giving multiple responses.

 

I am anticipating the graph to be like the one below but am getting challenging with bringing data under column of sesame, Sunflower, Soybean and poultry together for ease comparison.

SmartSelect_20220422-123242_WhatsApp.jpg

1 ACCEPTED SOLUTION

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCsgvzSkpqlTSUTIAYkM4HasTrRScmlicmJuqkF+SkVqEpAKiCqSCOBmELLKMIQomzr7i/Mqk1MS8YhSnwrTDJBWKU0HGIFluADegAOJdBXTnITxdXJqXlpNfnlqEMMYQQxE23wEtiAUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Preferred valuchains" = _t, Sesame = _t, Soybeans = _t, Sunflower = _t, Poultry = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Preferred valuchains", type text}, {"Sesame", Int64.Type}, {"Soybeans", Int64.Type}, {"Sunflower", Int64.Type}, {"Poultry", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each List.Sum({[Sesame],[Soybeans],[Sunflower],[Poultry]})),
    #"Grouped Rows" = Table.Group(#"Added Custom", {"Preferred valuchains"}, {{"Final Sum", each List.Sum([Custom]), type number}})
in
    #"Grouped Rows"

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately. If you have columns other than these, then delete Changed type step and do a Changed type for complete table from UI again) 

View solution in original post

3 REPLIES 3
Vijay_A_Verma
Super User
Super User

In terms of data, do you want sum of those 4 columns against those rows and then summarize on column1?

Yes! I want the sum of the 4 columns against the rows and then summarise on column1 but in away that it won't increase the numbers of rows. I tried unpivoting the 4 columns but it is increasing the number of rows hence affecting other dash boards

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCsgvzSkpqlTSUTIAYkM4HasTrRScmlicmJuqkF+SkVqEpAKiCqSCOBmELLKMIQomzr7i/Mqk1MS8YhSnwrTDJBWKU0HGIFluADegAOJdBXTnITxdXJqXlpNfnlqEMMYQQxE23wEtiAUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Preferred valuchains" = _t, Sesame = _t, Soybeans = _t, Sunflower = _t, Poultry = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Preferred valuchains", type text}, {"Sesame", Int64.Type}, {"Soybeans", Int64.Type}, {"Sunflower", Int64.Type}, {"Poultry", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each List.Sum({[Sesame],[Soybeans],[Sunflower],[Poultry]})),
    #"Grouped Rows" = Table.Group(#"Added Custom", {"Preferred valuchains"}, {{"Final Sum", each List.Sum([Custom]), type number}})
in
    #"Grouped Rows"

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately. If you have columns other than these, then delete Changed type step and do a Changed type for complete table from UI again) 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors