Forum Discussion
Rank by sorting columns
- 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
- 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] ) - 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.
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
Cmcmahan Iamnvt Thank you both!
At first I thought of resorting to adding a second table just for the ranking and make it look like they are the same table, but that wouldn't work out on PBI mobile (which my boss is adamant about us using), and as the list of units grow it would absolutely need scrolling, so I ruled it out.
I've come to the same conclusion as Cmcmahan a little late, then looked up if there was any way of showing a (dynamic) row number column on a table visual, but also came up with nothing. I've upvoted the idea, thanks!
I guess for now I'm just gonna tell my boss we'll have to make do without a ranking column, or maybe have to split the table into two :(
- jdbuchanan717 years agoSuper User
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] )- Clara7 years agoAdvocate II
jdbuchanan71 It would work wonders! I'm just worried the layman might try to sort by the headers anyway and decide it doesn't work. I might try it though :smileyhappy: Thank you!
- Cmcmahan7 years agoResident Rockstar
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.