How can I change the legend order in Power BI, and can you provide an example?

Power BI is a business intelligence software that allows users to create interactive visualizations and reports. The legend in Power BI is a key feature that displays the data categories or groups represented in a visual. It is possible to change the order of the legend in Power BI to better suit your reporting needs. This can be done by selecting the visual and then navigating to the Format pane, where you can rearrange the order of the legend items. As an example, if you have a bar chart representing sales by region, you can change the legend order to display the regions in ascending or descending order of sales. This feature provides users with greater control over the appearance and organization of their data in Power BI visuals.

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:

x