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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
bvy
Helper V
Helper V

Custom Sort on an axis -- but with one caveat

Hi. I want to do a custom sort on the x axis of a Line Chart. Consider this scenario: Salespeople visit a group of cities -- Atlanta, Boston, Chicago, Dallas, etc. and I want to display these cities on the x axis but in the order that the salespeople typically visit them

 

So if I have a slicer for salesperson and I select ANN, who visits Boston then Atlanta then Dallas. So for Ann, I want those cities in that order on the x axis. But BOB visits Atlanta then Chicago then Boston, so if I select Bob, I would want to see those cities in that order instead. 

 

I know I can configure a Sort By column and make it the default sort for some other field, but it requires a UNIQUE numerical assignment for each value. Here that's the city name and that won't work. 

 

I do NOT want to concatenate the salesperson's name to the city to put in the x axis. That will fix the issue but at the expense of cluttering up the x axis with redundant information, so that's not an option. The x axis should ONLY show the city name.

 

Any ideas? Thanks. 

 

1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

One way to do it would be to add a table that has the Rep, City, and Order for each then use that in a measure to calculate the order value, apply that measure in the tooltip so it can be used in the sort then sort the chart by the measure.

RepCityOrder table looks like this.

jdbuchanan71_0-1685203261303.png

This table is NOT joined into your main data table.  We use TREATAS to move the filters when we are calculating the order.

City Order =
CALCULATE (
    MAX ( RepCityOrder[Order] ),
    TREATAS (
        SELECTCOLUMNS ( Sales, "Rep", Sales[Rep], "City", Sales[City] ),
        RepCityOrder[Rep],
        RepCityOrder[City]
    )
)

Then we put that measure in the tooltip of the visual, this allows us to sort by that measure,

jdbuchanan71_1-1685203521665.png

This gives use the behavior you describe.

jdbuchanan71_2-1685203652744.png

jdbuchanan71_3-1685203698278.png

 

I have attached my sample file for you to look at.

 

View solution in original post

3 REPLIES 3
jdbuchanan71
Super User
Super User

Yep, it's the only way to get access to the value to use it for sorting.  Maybe someday they will add a sorting selection option.

bvy
Helper V
Helper V

Thanks. That works pretty well. I'd rather not have to carry around that value in the tooltip, but it's an acceptable compromise. 

jdbuchanan71
Super User
Super User

One way to do it would be to add a table that has the Rep, City, and Order for each then use that in a measure to calculate the order value, apply that measure in the tooltip so it can be used in the sort then sort the chart by the measure.

RepCityOrder table looks like this.

jdbuchanan71_0-1685203261303.png

This table is NOT joined into your main data table.  We use TREATAS to move the filters when we are calculating the order.

City Order =
CALCULATE (
    MAX ( RepCityOrder[Order] ),
    TREATAS (
        SELECTCOLUMNS ( Sales, "Rep", Sales[Rep], "City", Sales[City] ),
        RepCityOrder[Rep],
        RepCityOrder[City]
    )
)

Then we put that measure in the tooltip of the visual, this allows us to sort by that measure,

jdbuchanan71_1-1685203521665.png

This gives use the behavior you describe.

jdbuchanan71_2-1685203652744.png

jdbuchanan71_3-1685203698278.png

 

I have attached my sample file for you to look at.

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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