How Can the Legend Order be Changed in Power BI? (With Example)

The Legend Order in Power BI refers to the arrangement of the legend items in a visual, which can affect the display and interpretation of data. This order can be changed in Power BI by selecting the visual, navigating to the Format tab, and selecting “Legend” under the Properties section. From there, the user can rearrange the order of the legend items by dragging and dropping them or by using the “Sort by” option. For example, in a bar chart showing sales by product category, the legend order can be changed to show the categories in ascending or descending order by sales, allowing for a better understanding of which categories have the highest or lowest sales.


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