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

Power BI is turning 10! Letโ€™s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
hjolley
Regular Visitor

Using a Categorical Variable Parameter on Axis and Sort Reverting to Default.

I have a dashboard where I want to show two graphs side by side--one that is filtered by a variable and one that will always show the overall results for the same value. I was able to get this to work, however one of the axes of the graphs is a categorical variable parameter and every time I switch the parameter it switches back to default sorting behavior, which is by categorical variable. 

 

The effect of this is that that sometimes the categories I want to compare are not in the same order across both graphs, which disrupts their use as a comparison tool.

 

Here's an example of the problem based on the sample data:

 

hjolley_0-1726517656343.png

The month name filter only applies to the right graph while the parameter changes how profit is disaggregated between both.

 

I am able to use the "Sort Axis" option to sort by whatever variable is currently selected in the parameter, but as soon as the parameter changes it defaults back to sorting by the numeric variable and remains that way even when switching back to the parameter where the change was made.

 

Thank you for any help getting this to sort correctly. 

 

7 REPLIES 7
parry2k
Super User
Super User

@hjolley maybe you want to use matrix visual for this, add two measures, one for left and one for right, put both measures in the values section, while country on the rows, and then use data bar in conditional formatting. This way you will not run into this issue and the comparison will be super easy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! โค


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos ๐Ÿ™‚
Feel free to email me with any of your BI needs.

Unfortunately, I prefer the look of the column charts and the real measure is a complicated % of total that already makes use of ALLEXCEPT and I haven't been able to get one that doesn't react to the filter in question that also calculates correctly. 

Anonymous
Not applicable

Thanks for the reply from parry2k , please allow me to provide another insight:
Hi, @hjolley 

Your approach to sorting the columns is correct, but you need to sort each column selected by your parameter. For example:

Here is my sample data:

vlinyulumsft_0-1727060994937.png

vlinyulumsft_1-1727061046230.png

1.I have sorted each column based on the index column:

vlinyulumsft_2-1727061046231.png

vlinyulumsft_5-1727061074721.png

vlinyulumsft_4-1727061058491.png

2.Here is the final result, which I hope meets your requirements:

vlinyulumsft_6-1727061095745.png

vlinyulumsft_7-1727061095746.png

vlinyulumsft_8-1727061110653.png

 

Please note that the columns being sorted must not contain duplicate values, as this will result in a sorting error.

 

Please find the attached pbix relevant to the case.

 

Best Regards,

Leroy Lu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

All the categorical columns have duplicate values. I am plotting a metric against a changing categorical variable so all the values are a creation of many, many rows.

 

I'm not entirely sure why your PowerBI graphs don't have a default sort axis but the problem is that whatever I do it defaults back to the numeric metric like so:

 

hjolley_0-1727104662068.png

 

 

Vs yours, which does not in fact have a default sort at all:

 

hjolley_1-1727104705623.png

 

 

 

 

 

Anonymous
Not applicable

Hi, @hjolley 

Thank you for your swift response.

 

I apologise for any confusion caused. Your sorting method differs from mine. I use the position shown in the image below:

vlinyulumsft_0-1727105923085.png

If your sorting column contains duplicates, the corresponding index values for those rows must also be duplicated:

vlinyulumsft_1-1727105923086.png

 

I recommend using my method for sorting, as it can more effectively resolve your issue.

Of course, if you have any new ideas, you are welcome to contact us.
 

Best Regards,

Leroy Lu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

I have no concerns with the sort order of the categorical variable when I can get the graph to sort by the categorical variable. The problem is that my graphs for some reason will not stay sorted by the character variable.

 

I don't know why your graphs don't have a default sort axis (maybe because the data is already summarized?) but I believe that is the core of the problem, not what the categorical variables are sorted by (currently, they are sorted by themselves).

 

I don't care if the data remains in data source order; I care that two graphs sort the same way, whatever that is.

Anonymous
Not applicable

Hi, @hjolley 

Thank you for your swift response.

 

Your observation is very detailed. However, I need to clarify further:

 

In my visualisation, the reason for not using the default sorting and instead sorting by the index column is that I modified each columnโ€™s โ€œsort by columnโ€ setting and sorted by the index column.

 

This is why I recommend using the โ€œsort by columnโ€ method to sort the x-axis of your visualisation.

 

I hope my explanation is clear enough. If you have any further questions, please feel free to contact us.

 

Best Regards,

Leroy Lu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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