How to Change Legend Order in Power BI (With Example)

Often you may want to change the order of the items in a legend in Power BI.

Fortunately this is easy to do by creating a new column that specifies a custom order, then by using this new column as the legend in the chart.

The following example shows how to so in practice.

Example: How to Change Legend Order in Chart in Power BI

Suppose we have the following table in Power BI named my_data that contains information about items received, located, packed and shipped for two different retail stores:

Suppose that we would like to create a stacked column chart in which the bars in the chart are stacked in the following order:

  • Received
  • Located
  • Packed
  • Shipped

If we create a stacked column chart, Power BI will simply place the items in each bar in alphabetical order by default:

To specify a custom order for the items in the legend, we must first create a new column that assigns the following numeric values to the various categories:

  • Received – 1
  • Located – 2 
  • Packed – 3
  • Shipped – 4

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

Then type the following formula into the formula bar:

Stage Order = SWITCH('my_data'[Stage], "Received", 1, "Located", 2, "Packed", 3, "Shipped", 4)

This will create a new column named Stage Order:

Next, repeat the process to create another column that is a copy of the original Stage column by typing the following formula into the formula bar:

Stage Copy = 'my_data'[Stage]

This will create a new column named Stage Copy:

Next, with the Stage Copy column selected, click the Sort by column icon, then click Stage Order from the dropdown menu:

Next, switch back to the report view and click the stacked column chart to make it active.

Then drag the Stage Copy field under Legend:

Then right click Stage Copy, then click Rename for this visual, then name it Stage.

The items in each bar of the stacked column chart will now be sorted in the order that we specified:

Power BI change legend order

Additional Resources

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

Power BI: How to Apply Conditional Formatting to Bar Chart
Power BI: How to Show Both Value and Percentage in Bar Chart
Power BI: How to Only Show Top 10 Values in Chart

Leave a Reply

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