Skip to content
Advertisement

Sort Subplots (horizontal bar) based on a specified Rank Order

I have a subplot charted which has the categories that need to be displayed in a specific order. I’m working on the visual using PowerBI Python Script, so it looks like I’m unable to sort the dataframe as PowerBI does it automatically. In my dataset I have fruit_category, rnk, quantity_sold, forecast, goal, and stock quantity. The dataset should be ranked by rnk as it specifies the sort order for the fruit_category. However, I tried doing

JavaScript

but it’s not working. My guess is that it’s PBI not letting me do it. Here’s the graph:

enter image description here

Here’s my code:

JavaScript

How can I sort my fruits based on the rnk easily? Bonus question, I’m trying to avoid my value labels overlapping. Is there a way to avoid making them overlap? For example, the forecast number and the goal number for Mango is very close, so they are both overlapping.Thanks!!

Advertisement

Answer

You are sorting the dataset after assigning the values, do it before.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement