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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
mojganmeibodi19
Regular Visitor

sorting legend based on two criteria

I have a simple dataset that contains each supplier's sale in each year. I made a bar chart with years in the x axis and suppliers' sale on the y axis and used supplier company as legend.

Screenshot (11).png
I want to sort the legend (suppliers) in each bar (year) based on the total sales of that supplier in that specific year.
I can sort them by all-time total sales of suppliers, but I dont know how to do this sorting in each year.

6 REPLIES 6
josef78
Memorable Member
Memorable Member

Try Ribbon chart, and set transparency on connectors....

@mojganmeibodi19 I think @josef78 's proposal is the best answer.

lbendlin
Super User
Super User

Not possible in the standard visual.  May not even be possible in Deneb unless @dm-p has an idea.

Vega and Vega-Lite don't have sorting capabilities for more than one field using standard language constructs, but you can use transforms and window functions to create fields that dictate a sort order that you can then sort by.





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

Proud to be a Super User!


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




Could you layer the individual columns as separate marks with their own sort order? Or would you have to know the number of columns/marks beforehand?

Whatever the layer, if they share the same encoding channel, Vega will likely resolve them to the same scale (and sort). Your best bet would be to use a window transform to generate a numeric order based on grouping and sorting of multiple fields in the dataset and then sort on that.





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

Proud to be a Super User!


On how to ask a technical question, if you really want an answer (courtesy of SQLBI)




Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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