How to Sort Legend in Power BI Pie Chart
Sorting the legend on a Power BI pie chart should be simple, but it often sorts by the size of the slice instead of an order that makes sense to you, like alphabetical or chronological. This guide will walk you through the clear, straightforward steps to make your Power BI pie chart legend display in exactly the order you need.
Why Is It Tricky to Sort a Pie Chart Legend in Power BI?
By default, Power BI is designed to highlight the most significant data points. For a pie chart, this means it automatically sorts the wedges (and its corresponding legend) from the largest value to the smallest. While this is useful for quickly identifying top performers, it’s not always what you need for a specific report.
Perhaps you want to display sales regions alphabetically in the legend, or show project stages in a specific chronological order rather than by how much budget each stage holds. Power BI doesn't have a simple “Sort Legend Alphabetically” button. Instead, you need to provide a set of instructions within your data model to define the correct order. The most reliable way to do this is by using a feature called Sort by Column.
This technique involves creating a new, hidden "helper" column that contains a numerical order. You then tell Power BI to use this numerical column to sort your category column. Let's walk through exactly how to do it.
Free PDF · the crash course
AI Agents for Marketing Crash Course
Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.
Method 1: Using 'Sort by Column' With a Helper Column
This is the most common and versatile method for custom sorting in Power BI. You'll add a column directly to your existing data table that defines the sort order manually. We'll use a common scenario: a pie chart showing sales by product category that you want to sort alphabetically instead of by sales volume.
Step 1: Open the Power Query Editor
First, you need to access your data model to add the new sorting column. From the main Power BI Report view:
- Navigate to the Home tab on the ribbon at the top.
- Click on the Transform Data button. This will open the Power Query Editor in a new window, which is where you can reshape and clean your data.
Step 2: Create a Conditional Column as Your Sort Key
Now, let's create the column that will serve as our sorting key. This column will assign a number to each category based on the order you want.
- In the Power Query Editor, make sure your data table is selected on the left.
- Go to the Add Column tab in the ribbon.
- Click on Conditional Column. This opens a dialog box that lets you create a new column based on if/then logic.
In the "Add Conditional Column" window, you will set up rules. Let's say you have the categories 'Electronics', 'Apparel', 'Books', and 'Home Goods'. To sort these alphabetically, you would set it up like this:
- Give your new column a name, such as CategorySortOrder.
- Rule 1: If Column Name [Your Category Column] equals 'Apparel' then Output 1
- Rule 2: Click 'Add Clause' and set it to: If ... equals 'Books' then Output 2
- Rule 3: Click 'Add Clause' and set it to: If ... equals 'Electronics' then Output 3
- Rule 4: Click 'Add Clause' and set it to: If ... equals 'Home Goods' then Output 4
- For the Else field, you can put a high number like 99. This helps catch any future categories you might add so they don't break your sorting.
After clicking OK, you'll see your new CategorySortOrder column in your table. Now click Close & Apply in the Home tab to go back to the main Power BI window.
Pro-Tip: This method works for any custom order. If you want to sort months chronologically, you can create a conditional column where 'January' equals 1, 'February' equals 2, and so on.
Step 3: Apply the Sort by Column Setting
You've created the sorting logic, but you still need to tell Power BI to use it. This is the crucial step that links your category column to its new sort order.
- On the left side of the Power BI window, click on the Data view icon (it looks like a small spreadsheet).
- Find your data table in the Fields pane on the right and select it.
- Click on the header of the column you want to sort (e.g., your Product Category column). This will highlight the entire column.
- With the column highlighted, the Column tools tab will appear in the top ribbon.
- Click Sort by column and, from the dropdown, select your newly created helper column: CategorySortOrder.
Power BI will now process this logic in the background. It might take a moment, but you won't see an immediate change in the data table itself.
Step 4: Update Your Pie Chart Visual
Finally, go back to your report and adjust the visual's sorting settings.
- Click on the Report view icon on the left to return to your dashboard.
- Select your pie chart.
- Click the ellipsis (...) in the top-right corner of the visual.
- From the menu, hover over Sort by and select your category column (e.g., Product Category).
- Ensure the sort order is set correctly by hovering over the ellipsis again and clicking Sort ascending.
Your pie chart legend should now be sorted alphabetically ('Apparel', 'Books', 'Electronics', 'Home Goods'), regardless of which product category has the most sales!
Method 2: Creating a Separate Sorting Table (For Cleaner Data Models)
If your list of categories is long or if you need to reuse the same sorting logic across multiple tables, creating a separate sorting table is a much cleaner and more scalable approach. This keeps your sorting logic separate from your main business data.
Step 1: Create a New Table in Power BI
Instead of using Power Query, we'll create a small table directly in Power BI.
- In the Home tab, click on Enter Data.
- A "Create Table" window will appear. Here, you'll create two columns. Let's call them Product Category and CategorySortOrder.
- Manually enter your categories and their desired sort number, just like you did in the conditional column logic previously.
- Give the table a descriptive name, like "Category Sorting Table," and click Load.
Step 2: Create a Relationship Between Your Tables
Now you need to connect this new sorting table to your main data (often called your fact table).
- Go to the Model view on the left (the icon with three connected boxes).
- You will see your main data table and your new "Category Sorting Table."
- Find the Product Category column in your new sorting table and drag it onto the Product Category column in your main sales data table.
- A line will appear between the tables, indicating a relationship has been created. Power BI will typically detect a "one-to-many" relationship, which is correct.
Free PDF · the crash course
AI Agents for Marketing Crash Course
Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.
Step 3: Apply 'Sort by Column' on the New Table
This process is nearly identical to what you did in Method 1, but you'll apply it to the new dedicated sorting table.
- Switch to the Data view.
- From the Fields pane, select your "Category Sorting Table."
- Click on the Product Category column to highlight it.
- In the Column tools menu, click Sort by column and select CategorySortOrder.
Step 4: Update Your Pie Chart to Use the New Table
This is the final and most important step. Your visual needs to use the category field from the new sorting table, not the original data table.
- Go back to the Report view and select your pie chart.
- In the Visualizations pane, look at the field wells. You'll see your original Product Category in the "Legend" field well.
- From the Fields pane on the right, find your "Category Sorting Table." Drag the Product Category column from this new table into the "Legend" field well, replacing the old one.
- Just like before, click the ellipsis (...) on the visual, select Sort by > Product Category, and make sure it is set to Sort ascending.
Your chart will now sort based on the definitions in your clean, separate sorting table. This is considered a best practice in data modeling as it helps keep your model tidy and efficient.
Final Thoughts
Manually sorting legends in Power BI is a common hurdle, but it's easily managed once you understand the "Sort by Column" feature. By creating a helper column or a dedicated sorting table, you gain complete control over how your data stories are presented, allowing you to arrange categories alphabetically, chronologically, or in any custom sequence your report requires.
While mastering Power BI is a valuable skill, we know firsthand that building reports and dashboards from scratch can be slow, especially when you're manually creating helper columns and managing data models. We built Graphed to remove this friction. With our AI data analyst, you can connect your data sources and simply ask in plain English: "Show me a pie chart of sales by product category, sorted alphabetically." It instantly generates the live dashboard for you, saving you the time you'd spend configuring models and setting up sort orders manually.
Related Articles
Facebook Ads for Carpet Cleaners: The Complete 2026 Strategy Guide
Learn how to run Facebook ads for carpet cleaning businesses in 2026. Get proven strategies for targeting, creative formats, retargeting, and budget that actually convert.
Facebook Ads For Personal Trainers: The Complete 2026 Strategy Guide
Learn how to effectively use Facebook ads for personal trainers in 2026. This comprehensive guide covers targeting strategies, ad creative, budgeting, and optimization techniques to help you grow your training business.
Facebook Ads for HVAC Companies: The Complete 2026 Strategy Guide
Learn how to run high-converting Facebook ads for HVAC companies in 2026. This guide covers targeting, creative strategies, and proven campaigns that drive real leads.