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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
bernate
Helper III
Helper III

Sort Graph by 2 Categories

Hello!

I have the following graph. On the x axis I have date and employee name (the black bars are censored names). On the y axis I have sum of hours. 

bernate_0-1740787206282.png

I would like to sort the graph by date, then by sum of hours descending. It should look like below. I did this by adding sum of hours to the x axis between date and employee name, but now the graph is trying to show hours as well (and the dates are also descending).

bernate_1-1740787343041.png

Is there a way to sort the graph to show dates on the x axis in ascending order and to sort the bars that represent hours in descending order? I do not need any sort on employee name, but it still needs to be included on the x axis.

 

 

7 REPLIES 7
v-sdhruv
Community Support
Community Support

Hi @bernate ,
Just wanted to check if you had the opportunity to review the suggestions provided?
If the response has addressed your query, please accept it as a solution so that other members can easily find it.
Thank You

v-sdhruv
Community Support
Community Support

Hi @bernate ,
Just wanted to check if you had the opportunity to review the suggestions provided?
If the response has addressed your query, please accept it as a solution so that other members can easily find it.
Thank You

v-sdhruv
Community Support
Community Support

Hi @bernate ,
Just wanted to check if you had the opportunity to review the suggestions provided?
If the response has addressed your query, please accept it as a solution so that other members can easily find it.
Thank You

danextian
Super User
Super User

Hi @bernate 

 

Column chart can either be sorted by the value or by category only and not a combination of both so by default  this should be impossible. What you can do is to Rank time according to aggregation used in the visual and materialize this wrank using a disconnected table. Add the dimension from that disconnected table and sort using the categories (that dimension is considered a category).

 

 

The calculated table below generates a series of numbers from 1 to 24 (as there only 24 hours a day). The second column with invisible values is what will be used in the visual.

Ranks = 
SELECTCOLUMNS (
    GENERATESERIES ( 1, 24, 1 ),
    "Rank", [Value],
    "Rank2", REPT ( UNICHAR ( 8203 ), [Value] )
)

 

danextian_0-1740821312062.png

Create a measure that ranks the time. Note: I am using a separate time dimensions table called Hours.

Time Rank = 
RANKX ( ALL ( Hours ), [Sum of Value],, DESC, DENSE )

Create another measure to assign the materialize Time Rank by assigning the rank value to the Rank column in Ranks table.

Value by Rank = 
SUMX (
    FILTER (
        SUMMARIZECOLUMNS (
            Hours[Hour],
            "@rank", [Time Rank],
            "@value", [Sum of Value]
        ),
        [@rank] IN VALUES ( Ranks[Rank] )
    ),
    [@value]
)

 

Add Date, Rank2 and Time columns to the visual as well as the measure above. Expand the hierarchy up to the lowest level. Sort by category in ascending order.

danextian_1-1740821525772.png

Please see the attached pbix.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Ashish_Mathur
Super User
Super User

Hi,

I am not sure how much i can help but i would like to try.  Share the download link of the PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Irwan
Super User
Super User

hello @bernate 

 

to manage multiple value sort, i usually make another calculated column for sorting such as using CONCATENATE then put the new calculated column as tooltip value and use it as sort value.

 

i used CONCATENATE between x-axis and y-axis column value below.

Irwan_5-1740791779559.png

Irwan_3-1740791553574.png

 

you can CONCATENATE between date and y-axis as sort value, so it will group for same date as shown below.

Irwan_6-1740791804352.png

Irwan_4-1740791702161.png

 

Hope this will help.

Thank you.

Hi Irwan, unfortunately this did not work because my sum of hours per employee is not just one row. Some employees have multiple rows of hours listed per day. I could group by hours on employee name and date, but I have many other columns in the table where the values are different per row.

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.