Forum Discussion
Top N with Parameter?
Hello Community,
I’m curious if there's a workaround to pass a parameter for Top N filtering? I haven’t seen a good example, so wondering if you know some resources on this. Customer would like to select N number of legends to be displayed in a chart.
Thanks.
You would only need to add additional ALLSELECTED parameters to CALCULATETABLE if you are putting those additional columns on axes (or rows/columns) of the visual itself. If you are simply adding more slicers, then the existing measure would be fine.
However, a better way of defining the measure to capture all possibilities would be:
MyTopN3 = CALCULATE ( SUM ( LAWCrime[Violent crime total] ), KEEPFILTERS ( CALCULATETABLE ( TOPN ( [SelectedN], VALUES ( LAWCrime[State] ), CALCULATE ( SUM ( LAWCrime[Violent crime total] ) ) ), ALLSELECTED () ) ) )This uses ALLSELECTED () without arguments to ensure that the ranking is carried at the total level of the visual (this also means you can change ALLSELECTED ( LAWCrime[State] ) to VALUES ( LAWCrime[State] ).
If you want to rank by something other than state then just change the red part.
Cheers,
Owen :)
12 Replies
- OwenAugerSuper User
Here's an example from an earlier post, where N is selected by slicer
http://community.powerbi.com/t5/Desktop/Top-10-Other/m-p/52120#M20971
Is that the sort of thing you were looking for?
- captainlawMicrosoft Employee
Hello,
I referenced your other post, but I think my scenario might be slightly different. I've attached my file.
The chart on the right (DAX) is what I would like to match up with the chart on the left. By the user selection (5,10,50,100), the chart would render N number of States within the chart. I must have left out some isfiltered() condition somewhere that I am not sure how to resolve.
Your help is appreciated.
- captainlawMicrosoft Employee
I also tried the route of rankx, but for some reason it's not producing the correct rank. New column is named LawRank.