Forum Discussion
dynamic top 5 + others
- Anonymous4 years ago
Hey v-kkf-msft ,
Thank you so much for your reply and effort. The column is the same as the Location column, so the formula has no effect.
I came across a different solution from someone with the same question:
https://community.powerbi.com/t5/Desktop/Top-N-and-others-at-the-same-time/m-p/498687#M232598I created two unrelated tables:
- a table with all the location names and a row with "Other locations"
- Column: UNION(VALUES('SLA Cycles'[Location]), ROW("Location", "Other locations"))
- a table to slice for the amount of locations shown, default is set to 5
- Column: TopN locations= GENERATESERIES(1, 20, 1)Measure: TopN Value = SELECTEDVALUE('TopN locations'[Value], 5)Finally, I needed to create the measure:Top 5 + overige locaties =var thetopn = CALCULATETABLE(TOPN('TopN locations'[TopN Value], VALUES('SLA Cycles'[Locations]), [Tickets]))var other = ROW("Location", "Overige locaties")var allTheRest = CALCULATE([Tickets], EXCEPT(VALUES('SLA Cycles'[Location]), thetopn))var theUnion = UNION(thetopn, other)RETURNSUMX(INTERSECT(Location, theUnion),var currentIterator = Location[Location]RETURNIF(Location[Location] <> "Other locations",CALCULATE([Tickets], 'SLA Cycles'[Location] = currentIterator),allTheRest))I still don't understand why your and amitchandak formula didn't work as expected... The only other notable thing is that the measure 'Tickets' is a Distinctcount function; it counts the SLA codes, which is like this: DL-309 or DL-1588. And since we keep track of two important things, two rows with the same Code are created. So the column Location also returns two rows with the same Location name for one ticket.
- a table with all the location names and a row with "Other locations"
Anonymous , Try like
Top 5 locations + others =
VAR RankLocations = RANKX(
ALLSELECTED('SLA Cycles'[Location]),
CALCULATE([Tickets]),, DESC, Dense)
RETURN
maxx(values('SLA Cycles'[Location]), IF(RankLocations <=5, 'SLA Cycles'[Location], "Others"))
Hey amitchandak ,
Thanks for your reply. The formula returns a location which is ranked last...
The first part of the formule does the job
(RANKX(
ALLSELECTED('SLA Cycles'[Location]),
CALCULATE([Tickets]),, DESC, Dense))
So I assume the formula after Return is not correct yet. I hope you've another suggestion. And if necessary, I can share a sample data set.