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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
z-eitgeist
Frequent Visitor

Sorting categories/legend in stacked bar chart based on measure

Hey community,

 

I'm a little desperate after doing a lot of research on my issue but still didn't come up with a proper solution.

I hope you have some ideas on how to solve it.

 

Here's the challenge:

I'm showing yearly volumes per product models in stacked bar chart. The stacking order of the product models is crucial and I want to simulate different scenarios with different stacking orders. These scenarios are in a separate table.

z-eitgeist_0-1604767989627.png

 

Now I want the user to select a sorting scenario in the slicer. When changing the selection in the slicer, the sorting order in the bar chart should change according to the information in the table for the selected scenario.

 

But I have no clue how to implement it.

I think I can capture the selected scenario in the slicer in measure by using "selectedvalue". As it is shown in the card.

But how can I pull this measure for sorting?

 

For customized sorting I alway used calculated columns. But how to get the measure information in a column? My understanding was that calculated columns don't get updated by user actions.

 

I hope the given information help to get my problem and thanks for your support.

2 ACCEPTED SOLUTIONS
AlB
Super User
Super User

Hi @z-eitgeist 

hmm... tricky

The only thing I can think of now is to create several columns with Model1, Model2..., sorted by the corresponding sorting column and create one page per scenario, each using one of those columns in the legend. Then you can navigate from one page scenario to the other. In the service the user will see one page only. It's a clumsy solution/workaround though. Hopefully not much on your data model depends on the Model column. If it is used in any relationship it will become trickier.

Sharing a mock pbix with the basics of what you are trying to do would help 

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

View solution in original post

Hello @z-eitgeist,

What I think you can do is create two additional columns with the following data (or change your data)

Scenario + Model = Scenarios[Model] & " (" &Scenarios[Scenario_ID] &")"

Scenario + Index = Scenarios[Scenario_ID] & Scenarios[Sort_index]

Now sort the Scenario + Model column by the Scenario + Index column. What I'm creating is a column with unique values that identifies the model and adds a model in square brackets.

MFelix_0-1605095184068.png

Create a table with a unique model ID and use that table to ensure that the relationship between the two tables ensures that bidirectionality is enabled

MFelix_1-1605095263299.png

Now use the Scenario + Model column as your legend, Result below, and attach PBIX.

All you have to do is make a manual color selection for each model/combination scenario as using a legend does not allow condittional formatting.

MFelix_2-1605095458749.pngMFelix_3-1605095468935.png


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

7 REPLIES 7
AlB
Super User
Super User

perhaps  @MFelix  @TomMartens  will have other ideas

Hello @z-eitgeist,

What I think you can do is create two additional columns with the following data (or change your data)

Scenario + Model = Scenarios[Model] & " (" &Scenarios[Scenario_ID] &")"

Scenario + Index = Scenarios[Scenario_ID] & Scenarios[Sort_index]

Now sort the Scenario + Model column by the Scenario + Index column. What I'm creating is a column with unique values that identifies the model and adds a model in square brackets.

MFelix_0-1605095184068.png

Create a table with a unique model ID and use that table to ensure that the relationship between the two tables ensures that bidirectionality is enabled

MFelix_1-1605095263299.png

Now use the Scenario + Model column as your legend, Result below, and attach PBIX.

All you have to do is make a manual color selection for each model/combination scenario as using a legend does not allow condittional formatting.

MFelix_2-1605095458749.pngMFelix_3-1605095468935.png


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



Hello @MFelix ,

 

wow, that's awesome. Thanks a lot!

That's a smart solution. My ideas have been in a totally different direction and I would have never expected it to be so easy.

Thanks again!

I will implement it like this.

AlB
Super User
Super User

@z-eitgeist 

Don't assume... 🙂

Can you by any chance share the pbix? Or a dummy pbix with the basis model for what you are trying to do? I had another idea but need to run a couple of tests and don't have time to build the model myself.

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

 

Hello @AlB,

would be awesome if you have an alternative idea.

 

For any reasons I can't attach files in the forum. Please follow to link to find the mock-up file: https://www.dropbox.com/s/9kukr4rem0off57/example-SortingBySlicer.pbix?dl=0

I hope it helps.

AlB
Super User
Super User

Hi @z-eitgeist 

hmm... tricky

The only thing I can think of now is to create several columns with Model1, Model2..., sorted by the corresponding sorting column and create one page per scenario, each using one of those columns in the legend. Then you can navigate from one page scenario to the other. In the service the user will see one page only. It's a clumsy solution/workaround though. Hopefully not much on your data model depends on the Model column. If it is used in any relationship it will become trickier.

Sharing a mock pbix with the basics of what you are trying to do would help 

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

Hey @AlB ,

thanks for your feedback. 

Your proposal would work and I already assumed there wouldn't be an elegant solution. 
But I will try. 🙂

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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