In this post, we will learn how to perform a Power BI custom sort order in Stacked Bar Chart.

Custom Sorting in Power BI
If you try to build a new Stacked Bar Chart in Power BI, youโll notice that the default sort order is organized in descending order by the value of the Axis field, as shown below.

In our example, we have a table with the following columns that we need to sort in a specific order based on the column โStatusโ (High โ Medium โ Low).

In the Power BI Stacked Bar Chart, we have set the fields as below
- Axis: Status.
- Legend: Status.
- Values: Projects Count.

Also, we have tried to use the sort by column functionality in the visual option, as below

But it still doesnโt meet our needs because it sorts by field value rather than by our custom order needs (High โ Medium โ Low)!!!

Power BI Custom Sort order in Stacked Bar Chart
To overcome the Power BI Stacked Bar Chartโs default sort order behavior, we have to do the following:
Steps
- Create a Lookup table for the correponding column that you would like to sort by it.
- In the lookup table, Sort by column ID for Status column.
- Manage the relationship between the new lookup table and the original table.
- In Stacked Bar Chart, Set the Axis, Legend, with the new status field in the lookup table.
1) Create a Lookup Table in Power BI
As per your requirements, you have to create a new lookup table that will hold new main columns
- ID (A unique Identifier)
- Attribute (In our example, it will hold the correponding value for each status (High- Medium โ Low))
Steps
- At the โHomeโ tab, click on โEnter Dataโ to create a new table.

- The โCreate Tableโ should be opened now to add your lookup values.
- Add a column called โIDโ to serve as a unique identifier, and another called โStatusโ (or Attribute, if you want) to carry the corresponding values youโll need to sort it.
- Finally, set the Table name, and click Load to load the newly created table.

2) Sort by Column in Power BI
After loading the new table, you can find it in the โFieldsโ section, and now you have to sort the new lookup column Status by ID as the following:
Steps
- At the left side, Click on โDataโ icon.
- Make sure that the lookup table is shown as below.
- Click on Status column, then from the above ribbon, click on โSort By Columnโ and select โIDโ.

3) Manage Relationships in Power BI
Now, you just need to create a new relationship between the newly created lookup table and the original table as many to one by doing the following:
Steps
- At the left side, click on โModelโ Icon.
- From the above ribbon, click on โManage Relationshipsโ.
- Click on the โNewโ button to add a new relationship.

- At the first table, select the original table that holds the column you are need to sort.
- At the second table, select the newly created lookup table.
- Make sure that the columns have been mapped successfuly, and the โCardinalityโ is set to โMany to Oneโ, then click โOKโ.

4) Set Axis and Value Fields in Stacked Bar Chart
Now, you just need to set the Stacked Bar Chart Axis and Legend field to the โStatusโ column that has been created in the new lookup table as shown below.

5) Sort a Column with a Custom Order in Power BI
Great, the Stacked Bar Chart is now sorted by Status column in our custom order as shown below

Moreover, you can also specify the sort type in descending order as shown below.

You may be also intersted to read How to show Zero values in Power BI Chart?
Conclusion
By default, the Stacked Bar Chart in Power BI is ordered from highest to lowest value, and in this article, we have attempted to provide a simple method for sorting bar chart columns in a custom order as you prefer.
Downlaod
- You can download the PIBX file at Power BI Custom Sort Order Stacked Bar Chart, and donโt forget to follow Power BI Repoย to get more PIBX files samples with complex DAX formulas.