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
ncbshiva
Advocate V
Advocate V

Sort the Order in the Stacked Bar chart

Hi Team,

 

My requirement is to sort the order in the Stacked bar graph as shown below. As you can see in the first stacked bar graph the Medium with value 3 is on top  and then Hard with value 2 is at bottom . I want this to be reversed means Hard with red color value 2 should come on top and then the Medium with value 3 should come bottom.

 

Here the legend is a "Calculated Column".

TPOD.png

 

 

Thanks in advance.

1 ACCEPTED SOLUTION

Hi ,

 

I got the solution , i tried to create separate measures for hard,medium and easy and use them in Value box and arrange these measures as added so that it sorts the column charts as required.Chart.jpg

 

View solution in original post

12 REPLIES 12

Hi,

 

you can change the sort order, using the "Sort by Column" button.

https://docs.microsoft.com/en-us/power-bi/desktop-sort-by-column#sort-using-the-sort-by-column-butto...

 

Create a column with the sort order for each category ...

e.g. 3 (Hard) > 2 (Medium) > 1 (Easy)

... and use these with "Sort by Column" as surrogate sort column

 

best regards

 

Marcus

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


Hi,

 

Here my category column is calculated one and below is the formula for it.

 

IFCondition = IF('Capability Data'[Difficulty to Fill]="Hard" && 'Capability Data'[How large is the gap to fill]="1";"Hard";
IF('Capability Data'[Difficulty to Fill]="Hard" && 'Capability Data'[How large is the gap to fill]="2";"Hard";
IF('Capability Data'[Difficulty to Fill]="Hard" && 'Capability Data'[How large is the gap to fill]="3";"Hard";
IF('Capability Data'[Difficulty to Fill]="Medium" && 'Capability Data'[How large is the gap to fill]="3";"Hard";
IF('Capability Data'[Difficulty to Fill]="Medium" && 'Capability Data'[How large is the gap to fill]="1";"Medium";
IF('Capability Data'[Difficulty to Fill]="Medium" && 'Capability Data'[How large is the gap to fill]="2";"Medium";
IF('Capability Data'[Difficulty to Fill]="Easy" && 'Capability Data'[How large is the gap to fill]="3";"Medium";
IF('Capability Data'[Difficulty to Fill]="Easy" && 'Capability Data'[How large is the gap to fill]="1";"Easy";
IF('Capability Data'[Difficulty to Fill]="Easy" && 'Capability Data'[How large is the gap to fill]="2";"Easy";BLANK()
)))))))))
 
And if i create a new calculated field for the sorting and use that in the Sort by columns , i am getting below error.
Tpod1.PNG

 

 
 

Hello,

 

Can anyone please help me with this sorting issue ?

 

Regards

Hi,

 

could you calculate the category column in Power Query (M-Code)?

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


Not sure how to calcuate in M-code. I am not aware of the language.

Hi,

 

that should help.

Add a custom column and calculate the catorgary column.

https://docs.microsoft.com/en-us/power-bi/desktop-add-custom-column

 

https://docs.microsoft.com/de-de/powerquery-m/power-query-m-language-specification

 

If expression

The if expression selects between two expressions based on a logical condition.

For example:

if 2 > 1 then
     2 + 2
else
    1 + 1

 

The first expression (2 + 2) is selected if the logical expression (2 > 1) is true, and the second expression (1 + 1) is selected if it is false. The selected expression (in this case 2 + 2) is evaluated and becomes the result of the if expression (4).

 

 

 

 

 

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


Gilbert Quevauvilliers blogged this today.

Multiple conditions for a conditional column in Power Query

https://www.fourmoo.com/2018/11/27/multiple-conditions-for-a-conditional-column-in-power-query/

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


Nope i am getting the same error.

Hi ,

 

I got the solution , i tried to create separate measures for hard,medium and easy and use them in Value box and arrange these measures as added so that it sorts the column charts as required.Chart.jpg

 

Ops, i think now i understand the error message...

In your soultion you have more than one value in 'Sort' for the same value in 'IFCondition'.

 

I think your column IFCondition is part of the table 'Capability Data' and you create the Sort column in this way.

 

 

Sort = IF('Capability Data'[IFCondition]="Hard";3;
       IF('Capability Data'[IFCondition]="Medium";2;
       IF('Capability Data'[IFCondition]="Easy";1;0
       )))

 

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


themistoklis
Community Champion
Community Champion

@ncbshiva

 

Cick on the 3 dots on the top right of the object:

1. Sort by (select the Measure)

2. Sort Ascending 

Hi,

 

The is not working , it is changing the position of the x-axis.

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.