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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
confidentnwrong
Advocate I
Advocate I

Sort bar chart by category

Hi everyone !

 

I have a bar chart like this : 

confidentnwrong_0-1675951405115.png

I'd like to have all the pink together, then all the blue, etc on the same bar chart, while keeping the current order within a given color group.

 

If you need more context, these are average GPAs of different schools, color coded by states. And here is my model :

Model2.png

Thank you !

 

1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

@confidentnwrong 

You can sort a chart using a measure that is not on the chart by adding the measure to the tooltip.

jdbuchanan71_0-1675955708386.png

Then setting the sort on the chart to use the measure:

jdbuchanan71_1-1675955772591.png

Now the sort measure.  First it calcualtes an alphabetical ranking of the states and multiplies that by 100 then adds the ranking of the school based on [Average GPA].  The * 100 + school ranking returns something like:
All Arizona schools are ranked 1__ then the shool ranking is added on so we get 101, 102, 103 for Arizona schools, 201, 202, 203 for California schools, etc.

Sort Measure = 
DIVIDE ( [AVG GPA], [AVG GPA] ) * 
    (
        RANKX(ALL(FactTable),CALCULATE(MAX(FactTable[State])),,ASC,Dense) * 100 +
        RANKX(ALL(School),[AVG GPA],,DESC,Dense)
    )

The 
DIVIDE ( [AVG GPA], [AVG GPA] ) *

Keeps the ranking from calculating where there is no GPA.
I have attached my sample file for you to look at.

View solution in original post

2 REPLIES 2
jdbuchanan71
Super User
Super User

@confidentnwrong 

You can sort a chart using a measure that is not on the chart by adding the measure to the tooltip.

jdbuchanan71_0-1675955708386.png

Then setting the sort on the chart to use the measure:

jdbuchanan71_1-1675955772591.png

Now the sort measure.  First it calcualtes an alphabetical ranking of the states and multiplies that by 100 then adds the ranking of the school based on [Average GPA].  The * 100 + school ranking returns something like:
All Arizona schools are ranked 1__ then the shool ranking is added on so we get 101, 102, 103 for Arizona schools, 201, 202, 203 for California schools, etc.

Sort Measure = 
DIVIDE ( [AVG GPA], [AVG GPA] ) * 
    (
        RANKX(ALL(FactTable),CALCULATE(MAX(FactTable[State])),,ASC,Dense) * 100 +
        RANKX(ALL(School),[AVG GPA],,DESC,Dense)
    )

The 
DIVIDE ( [AVG GPA], [AVG GPA] ) *

Keeps the ranking from calculating where there is no GPA.
I have attached my sample file for you to look at.

That's absolutely perfect, thank you so much !

 

My Average GPA was actually not a measure but a field in the FactTable (forgot to show it in my simplified model) but using 

MAX(FactTable[Average GPA])

instead of just [Average GPA] solved that issue 🙂 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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