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

2 Replies to “How to Change Legend Order in Power BI (With Example)”

  1. Hi Zach, I understand your example, but what if you have a stacked column chart with multiple measures (say, Orders, Sales, Profit) and you want to order the legend? You’ll find that you can display your measures in a meaningful order (Orders at the bottom, then Sales, Profit on top), but the legend order will be the exact reverse. Would you have any solution for that? Thanks, Paul

    1. You’re absolutely right—when using a **stacked column chart** in **Power BI** with **multiple measures**, the order in the legend is typically the **reverse of the stacking order**. Unfortunately, **Power BI does not currently allow manual reordering of legend items** when multiple measures are used directly.

      ### Why It Happens:

      Power BI stacks measures in the order they are added (from bottom to top), but it renders the legend from **top to bottom**, leading to the reversed order in the legend.

      ### Workarounds to Control Legend Order

      Here are two effective approaches to fix or work around this:

      —

      ### **Option 1: Use Unpivoted Data with a Single Measure and Category Field**

      This is the **recommended** solution.

      #### Steps:

      1. In Power Query (Power BI Editor), **unpivot** your measures (Orders, Sales, Profit) so you end up with:

      * One column for **Measure Type** (e.g., “Orders”, “Sales”, “Profit”)
      * One column for **Value**

      2. Load this back into your data model.

      3. Create a custom **sort order** for the Measure Type:

      * Create a calculated table or a mapping table like:

      “`
      MeasureSort = DATATABLE(“Measure”, STRING, “SortOrder”, INTEGER, {
      {“Orders”, 1},
      {“Sales”, 2},
      {“Profit”, 3}
      })
      “`
      * Set the `Measure Type` column to be **sorted by SortOrder**.

      4. Use a **stacked column chart** with:

      * Axis: Date or Category
      * Value: Value
      * Legend: Measure Type

      Now the legend and stacking order will align as intended.

      —

      ### **Option 2: Reverse the Measure Input Order (Reverse Stack)**

      This is a **limited workaround**.

      If you’re using **measures directly** in the Value well of a stacked column chart, you can try **reordering how they are added** to reverse the stack. But since this will change the **stacking order**, it may not meet your visualization intent.

      —

      ### Summary

      To achieve full control over **both stack order and legend order**, **unpivoting your data** and using a category field for the legend is the most effective and flexible method. This also future-proofs your report for tooltips, conditional formatting, and dynamic visuals.

Leave a Reply

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