sorting stack bar chart in power BI

落花浮王杯 提交于 2019-12-13 01:48:07

问题


I am using a stacked bar chart for presenting the gender ratio in various region. here the legend is gender and Axis is region and value is headcount. when i want to sort the chart according to female gender value . the sorting is only done by the headcount value. how can i sort it for the percentage value. please help me.


回答1:


EDIT: My first answer focused only on count, now I've taken into account that OP wants to sort by percentage female value


You can sort your data directly in your Stacked column chart visualization, after pivoting the data and adding a column showing the female percentage value using the Power Query Editor. If you insert the female ratio as a Tooltip, your chart can be sorted as that value even though it is not displayed in your chart.

Here are the details:


This data sample should fit your description:

Region,Gender,Count
USA,M,9000
USA,F,7000
EU,M,5000
EU,F,5000
UK,M,2000
UK,F,4000
CAN,M,100
CAN,F,900

If you enter that data using Edit Queries / the Power Query Editor, you can set it up like this:

Now highlight the Gender column, and select Transform > Pivot Column to get this:

Under Values Column, select Count and click OK to get this:

Now simpy add a custom column to calgulate the female ratio like so:

Now your table should look like this:

In the desktop, insert a stacked column chart and set it up like below. Notice that you'll need to insert F ratio under Tooltips:

Now you can sort your chart by Ascending or Descending F ratio



来源:https://stackoverflow.com/questions/52424336/sorting-stack-bar-chart-in-power-bi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!