Forum Discussion

Clara's avatar
Clara
Advocate II
7 years ago
Solved

Rank by sorting columns

I have a table visual with 4 columns. One lists all units in my company, two of them show percentual values by unit and the other ranks each unit by their values. I want to be able to sort by one of ...
  • Cmcmahan's avatar
    Cmcmahan
    7 years ago

    So I've actually spent WAY  more time than is necessary trying to figure out this issue.  It should be essentially the same use case as adding a row number to a table visual.  However, it doesn't seem like there is a way (even a crazy workaround) to do this unless you're sorting by one column at all times.   It makes sense, but there just doesn't seem like there's a way to determine what the current sort column/order of a visual is in a measure.   

     

    You could try to hack it by adding a 2nd table that just has rank # in it and moving it so that it looks like it matches the table of values, but that won't be linked to the first table's current slicer selection or any scrolling.

     

    I was thinking about setting up some sort of slicer option that essentially switches between two RANK measures based on the user clicking some slicer option that also switches the sort order, but then  the sort by functionality of the table would break it anyway. 

     

    I've gone ahead and voted for this improvement here: https://ideas.powerbi.com/forums/265200-power-bi-ideas/suggestions/19331770-row-number and I suggest you do too

  • jdbuchanan71's avatar
    jdbuchanan71
    7 years ago

    Clara If it would be acceptable for the users to select the column to sort by in a slicer instead of the matrix then Cmcmahan idea of a ranking over a switch would work.  You just have to set up a table of the values to sort by and modify your ranking formula. 

    You can even make the table just using a DAX formula, here is an example from one of my models.

    =DATATABLE( 
    	"Top N Measure", STRING,
    	"Order",INTEGER,
    {
    
    {"Billed $",1},
    {"Allowed $",2},
    {"Not Covered $",3},
    {"Paid $",4},
    {"Claim Count",5},
    {"Claimants",6},
    {"Claim Lines",7},
    {"Avg Billed Line Amount",8}
    }
    )

    Then I read the users selecton in the switch, you would do your ranking over this.

    TopN Measure Calc:= 
    VAR SelectedMeasure = SELECTEDVALUE ( ctTopNMeasures[Top N Measure], "Paid $")
    
    RETURN
    SWITCH ( TRUE (),
        SelectedMeasure = "Billed $", [Billed Amount],
        SelectedMeasure = "Allowed $", [Allowed Amount],
        SelectedMeasure = "Not Covered $", [Not Covered Amount],
        SelectedMeasure = "Paid $", [Paid Amount],
        SelectedMeasure = "Claim Count", [Claim Count],
        SelectedMeasure = "Claimants", [Claimant Count],
        SelectedMeasure = "Claim Lines", [Claim Lines Count],
        SelectedMeasure = "Avg Billed Line Amount", [Avg Billed Line Amount]
    )
  • Cmcmahan's avatar
    Cmcmahan
    7 years ago

    You might be able to get real clever and hide the headers of the table or cover the header row with a text box so that the user can't click the sorting option.