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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Fusilier
Helper III
Helper III

Sort 100% stacked bar chart for survey

Hi, hope somebody can help?

I have some survey data I'm trying to analyse.

Response to a question is either:

Fairly safe

Fairly unsafe

Neither safe nor unsafe

Very safe

Very unsafe

 

And the responses are grouped by age (55-64, 65+ etc.) of the respondent.

 

I've created this 100% stacked bar chart :

safety.png

I'm trying to sort the chart by 'the Fairly safe %' descending.

I've searched online and followed a suggestion of creating  a measure and adding it as a tooltip and then sorting the axis by the tooltip:

Count Answer Fairly safe =
CALCULATE(
    COUNTROWS('All Responses (2)'),
    'All Responses (2)'[Value]="Fairly safe"
)
The chart is sorting by the count of the value "Fairy safe", but I want it to sort by the % of the value not the count. So I want to see from top to bottom: 38% followed by 34% then 31% and so on.
Is there a way of changing the measure to calculate the % and not the count?
1 ACCEPTED SOLUTION
Ritaf1983
Super User
Super User

Hi @Fusilier 
If you need to sort the stacked graph by its "slices"  you need to create separate measures for every group at the legend like :

Fairly safe = CALCULATE(COUNTROWS('Table'),'Table'[answer]="Fairly safe")
Fairly unsafe = CALCULATE(COUNTROWS('Table'),'Table'[answer]="Fairly unsafe")
Neither safe nor unsafe = CALCULATE(COUNTROWS('Table'),'Table'[answer]="Neither safe nor unsafe")
Ritaf1983_0-1722603370575.png

Then you can select by which group you want to sort the graph :

Ritaf1983_1-1722603423518.png

The pbix with the example is attached
P.s It's important to note that stacked graphs are complex to read and not really effective for data visualization. I'm attaching a link to my article on the subject, including an alternative.

https://www.madeiradata.com/post/home-experiments-and-stacked-bar-graphs

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

View solution in original post

3 REPLIES 3
Ritaf1983
Super User
Super User

Hi @Fusilier 
If you need to sort the stacked graph by its "slices"  you need to create separate measures for every group at the legend like :

Fairly safe = CALCULATE(COUNTROWS('Table'),'Table'[answer]="Fairly safe")
Fairly unsafe = CALCULATE(COUNTROWS('Table'),'Table'[answer]="Fairly unsafe")
Neither safe nor unsafe = CALCULATE(COUNTROWS('Table'),'Table'[answer]="Neither safe nor unsafe")
Ritaf1983_0-1722603370575.png

Then you can select by which group you want to sort the graph :

Ritaf1983_1-1722603423518.png

The pbix with the example is attached
P.s It's important to note that stacked graphs are complex to read and not really effective for data visualization. I'm attaching a link to my article on the subject, including an alternative.

https://www.madeiradata.com/post/home-experiments-and-stacked-bar-graphs

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Thank you,

I read your article as well and will try your alternative method as well.

Thank you very much, nothing makes me happier than a complicated graph being discarded in favor of effective visualization 🙂😍

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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