How to Sort a Stacked Column Chart in Power BI (With Example)


Often you may want to sort a stacked column chart in Power BI based on the total height of the bars in the chart:

This is easy to do by creating a measure that calculates the sum of each column.

The following example shows how to do so in practice.

Example: How to Sort a Stacked Column Chart in Power BI

Suppose we have the following table in Power BI named my_data that contains information about points scored by various basketball players during three different games:

Suppose we would like to create a stacked column chart that displays the total points scored by each player during each game.

If we would like to be able to sort the bars based on the total height of each bar, we will first need to create a new measure that contains the sum of points scored by each player across all three games.

To do so, click the Table tools tab, then click the New measure icon:

Then type the following formula into the formula bar:

Sum Points = CALCULATE(SUMX('my_data', [Game 1] + [Game 2] + [Game 3]))

A new measure named Sum Points will be created that contains the sum of the points scored by each player across all three games:

Next, switch to the Report View and click the Stacked column chart icon under the Visualizations tab.

Then drag Team under the X-axis, drag Game 1, Game 2 and Game 3 under the Y-axis, and drag Sum Points under Tooltips:

This will produce the following stacked column chart:

The bars are currently sorted in descending order based on the value in the Game 1 column.

To instead sort the bars by the total points scored by each player, click the three horizontal dots in the top right corner of the chart, then click Sort axis, then click Sum Points:

 

The bars in the chart will automatically be sorted based on the total points scored by each player in descending order:

Power BI sort stacked column chart

Additional Resources

The following tutorials explain how to perform other common tasks in Power BI:

Power BI: How to Calculate Sum with Filter
Power BI: How to Rank Values by Group
Power BI: How to Use SUM IF

Leave a Reply

Your email address will not be published. Required fields are marked *