Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
junmin
Advocate I
Advocate I

Sort two columns on the same one column

I would like to create a bar chart with these columns: Category, Subcategory, Quantity

 

The x axis will be both Category and Subcategory.

 

The y axis will be Quantity.

 

I want to sort Category and Subcategory by descending order of Quantity. What this means is Category bars will be from tallest bar to shortest. Then, after drilling down, the Subcategories belonging to each Category will also be sorted from tallest bar to shortest bar.

 

I've tried:

 

1. Transform Data > Group by Category with Sum of Quantity as aggregation > Sort > Add Index > Sort Category column with Index 

 

- this doesn't work because I have other columns in the same table which I'm using as Slicer.

 

2. The same thing as #1 but on Subcategory 

 

- doesn't work as well. Same reason as #1

 

3. Add Category, Subcategory and Quantity in a Table visual > Shift click on Category and Quantity > Change Table visual to Bar chart 

 

- this doesn't work because although the Subcategories will sort in descending order of Quantity within their respective Category, the Category is not sorted by Quantity but by alphabetical order.

 

4. The same thing as #3 but shift click on all three columns

 

- doesn't work because it results in the default sort of the existing data.

 

I've ran out of ideas. Please help! 😞

 

 

Edit: I found the solution on YouTube! Link: https://youtu.be/RDXvpE3V5m0?si=NA5s7BVR5Xu9yy6g

1 ACCEPTED SOLUTION
junmin
Advocate I
Advocate I

8 REPLIES 8
junmin
Advocate I
Advocate I

I found the solution on YouTube! Link: https://youtu.be/RDXvpE3V5m0?si=NA5s7BVR5Xu9yy6g

HarishKM
Memorable Member
Memorable Member

@junmin Hey,
Kindly use cluster column chart for your requirmeent.

Please refer below example for your reference.

HarishKM_0-1744367567912.png


I am following below steps.

select Cluster column chart

drag your cat and sub cat to x axis

drag your QTY measure to value.

select three dot on right side - select sort by QTY then select ASC order to sort as per your requirment.

 

Thanks

Harish M

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Add snapshop for your reference

Hi @HarishKM 

  • Unfortunately this will not work for me because if you were to set the subcategories quantities to be different, for example if bb is more than aa but bb2 is less than aa1, the categories would be sorted according to the quantities so the sub category of bb2 will be before aa1, causing the category not sorted by quantity
barritown
Super User
Super User

Hi again,

 

Here is an advanced version of this approach which should work in more complicated scenarios.

The idea is to create a measure which generates a sorting order value consisting of two parts: the whole part is responsible for sorting categories, the decimal part - for sorting subcategories.

 

barritown_0-1744362612903.png

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

Hi! Sorry for the incredibly late reply. It doesn't quite work somehow. But good news, i found a video online that solves my problem. Thank you so much for your time !! 

Hi @barritown

Let me try this and update here again soon. Thank you 

barritown
Super User
Super User

Hi @junmin,

I can offer you to create a sorting option like this one:

barritown_0-1744296174899.png

With your real data it can be more complicated.

Once done, you can add it to Tooltips, then it will be available among the sorting options.

If you drill down, you will get what you want with subcategories:

barritown_1-1744296548745.png

Best Regards,

Alexander

My YouTube vlog in English

My YouTube vlog in Russian

Hi @barritown 

Thanks for this. However, as you've expected, my data is a bit more complicated, hence I'm unable to get the expected result. Thank you very much for your work book as reference too.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors