Change the Legend Order in a Chart in Power BI
Change the Legend Order in a Chart in Power BI, Customizing the layout of your charts in Power BI can help you visualize your data more effectively.
One common task is to change the order of the items in a legend, but doing this can sometimes be a challenge.
In this article, we’ll show you how to easily change the legend order in a chart in Power BI.
Change the Legend Order in a Chart in Power BI
We’ll walk you through a step-by-step example of how to reorder the items in a stacked column chart, so you can apply the technique to your own dashboards and reports.
Example: Changing Legend Order in a Stacked Column Chart
Let’s say you have a table named my_data
that contains information about items received, located, packed, and shipped for two different retail stores.
You want to create a stacked column chart where the items are ordered in the following sequence:
- Received
- Located
- Packed
- Shipped
Power BI will default to ordering items alphabetically, but you can change this by creating a new column that specifies a custom order.
Step 1: Create a New Column for Custom Order
First, you need to create a new column that assigns a numeric value to each category.
This will tell Power BI in which order to display the items in the legend.
To do this:
- Click the Table tools tab and then click the New column icon.
- 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
.
Step 2: Create a Copy Column and Sort It
Next, you’ll create a copy of the original Stage
column. This will allow you to sort it based on the custom order you just specified.
To do this:
- Type the following formula into the formula bar to create a new column:
Stage Copy = 'my_data'[Stage]
This will create a new column named Stage Copy
.
- Select the
Stage Copy
column and click the Sort by column icon. - Click Stage Order from the dropdown menu.
Step 3: Update the Legend Order
Now that you have the Stage Copy
column sorted, you can update the legend order in your chart.
To do this:
- Switch back to the Report view and click the stacked column chart to make it active.
- Drag the
Stage Copy
field under Legend. - Right-click the Stage Copy field and select Rename for this visual.
- Name the field Stage.
Result: Custom Legend Order
When you follow these steps, you should see that the items in each bar of the stacked column chart are now sorted in the order you specified.
This technique allows you to customize the layout of your charts and make your data visualizations more effective.
By applying this method, you can easily change the legend order in a chart in Power BI, making it easier to communicate insights and trends in your data.