Power BI Tip — How to custom sort categorical/text columns in a bar chart?

Yannawut Kimnaruk
3 min readMay 16, 2022

--

Summary

  1. Click on Enter data in the Home tab and create a table with 2 columns.
    The first column is the category and the second column is the order of that category.
  2. Link the original tables and a new table in the Model view.
  3. Sort by an “order” column in the Data view
  4. Use a column from a new table to create a graph

Introduction

When creating a bar or column chart, an axis presents categorical data (Y-axis for a bar chart, X-axis for a column chart). You may want to sort this axis when you know this category has an order from low to high.

However, in Power BI, You can only sort axis by alphabetic or value.

In this article, I will show how to solve this problem.

Example

I created a bar chart between company size and the number of employees who want to change jobs.

The bar chart is illustrated below.

Company size should be ordered from a small to a large size such as <10 should be above 10–49.

Methodology

  1. Click on Enter data in the Home tab and create a table with 2 columns.
    The first column is the category and the second column is the order of that category.

2. Link the original tables and a new table in the Model view.

Dragging company_size from a new table in step 1 to company size in the original table.

⚠️ Make sure that connection is 1 — *

3. Sort by an “order” column in the Data view

Data view > Click a new table > select column “company_size” > Go to “Column tools” menu bar > Sort by column > Order

4. Use a column from a new table to create a graph

Change a parameter in the Axis field to “company_size” from a new table.

That is it!!

We get a bar chart the Y-axis is ordered as we want.

--

--

Yannawut Kimnaruk
Yannawut Kimnaruk

Responses (2)