Search code examples
powerbipowerbi-desktop

Order manually the legend in a PowerBI line chart


I have the following chart in PowerBI

enter image description here

I would like to put the legend order exactly like the lines order (the line at the bottom receives the first legend, and so on). Any way to do that?


Solution

  • In the transformation layer, add a new custom column "sort_order" with this similar code-

    if [Item No] = "ITEM-A" then 2 else if [Item No] = "ITEM-B" then 1 else 3
    

    Here is the output in my table-

    enter image description here

    Now in the table visual see how the Item No ordered with default setup when I add the column with an aggregated value. This is basically following the default Asscending order-

    enter image description here

    Now, to change the order of Item No, we need to order the column based on another (sort_order) column as shown below in the Table View window.

    enter image description here

    And here is the new custom order for column Item No-

    enter image description here