Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

sort 100% stacket column chart by created measure

Hello everyone, I have the followin stacket column chart, and I woukd like to sort the the percent values and is not working by the ordinary way. I only have the option below., and if the I choose market share asc or desc nothing happens, there's a way to put the the the larger number at the end and grow the stacked till the lowest? In the image is working cause a I put some space/tab into the name of legend.

 

 

 

The measure is 

Market Share =

VAR RAT =
sum(SOA[Rat_Per])

var allRAT =
CALCULATE( sum(SOA[Rat_Per]), ALL ( SOA[Owner]))

RETURN
DIVIDE(RAT,allRAT)

 

  • I don't know an easier way other than what you've tried to do with the legend.

    You can however, do the same thing without it visibly affecting the legend.

     

    I do something similar to control complex table sorting requirements with this...

    SortUnderHours = 
    //UNICHAR(8203) is a zero width space REPT() repeats a character x many times.
    //More spaces sort at the top when in DESC order.
    
    VAR __HR = [HoursRemaining]
    VAR __DCE = [DaysToCycleEnd]
    VAR __HRCD = [HoursRemaining_CycleDays]
    VAR _c = 8203
    RETURN
    SWITCH
        (TRUE()
            , __HR <= 0, BLANK()
            , AND(__DCE = 0, __HR > 0), REPT( UNICHAR(_c) , 3)
            , __HRCD > 12, REPT( UNICHAR(_c) , 5)
            , __HRCD >= 8, REPT( UNICHAR(_c) , 4)
            , __HRCD < 8, REPT( UNICHAR(_c) , 2)
            , BLANK()
    
        )
    

     

    You could adapt this for your legend potentially to control the sorting. It'll take some work which I don't have time for right now but hopefully it'll get you started.

     

     

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

    It is not supported to sort a stacked column chart by value in Power BI currently .There is an idea about this issue, please vote it up,  Stacked bar chart total sort , to improve the Power BI.

     

    I have also found a similar post, please refer to it to see if it helps you.

    Stacked column chart: Sort legend by value, not alphabet 

    • If you have only one category on X-axis, you can have your Legend column sort by Value column.
    • If you have multiple catgories on X-axis, this method will not work. You have to manually define the order column in your table. 

    Best Regards

    Community Support Team _ Polly

     

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

  • KNP's avatar
    KNP
    Icon for Super User rankSuper User

    I don't know an easier way other than what you've tried to do with the legend.

    You can however, do the same thing without it visibly affecting the legend.

     

    I do something similar to control complex table sorting requirements with this...

    SortUnderHours = 
    //UNICHAR(8203) is a zero width space REPT() repeats a character x many times.
    //More spaces sort at the top when in DESC order.
    
    VAR __HR = [HoursRemaining]
    VAR __DCE = [DaysToCycleEnd]
    VAR __HRCD = [HoursRemaining_CycleDays]
    VAR _c = 8203
    RETURN
    SWITCH
        (TRUE()
            , __HR <= 0, BLANK()
            , AND(__DCE = 0, __HR > 0), REPT( UNICHAR(_c) , 3)
            , __HRCD > 12, REPT( UNICHAR(_c) , 5)
            , __HRCD >= 8, REPT( UNICHAR(_c) , 4)
            , __HRCD < 8, REPT( UNICHAR(_c) , 2)
            , BLANK()
    
        )
    

     

    You could adapt this for your legend potentially to control the sorting. It'll take some work which I don't have time for right now but hopefully it'll get you started.

     

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi, Can u please explain in detail  how it got resolved.