Forum Discussion

MichaelaMul's avatar
MichaelaMul
Icon for Helper III rankHelper III
1 year ago
Solved

Slicer with Top N

Hello! I was wondering if there's a way to create a slicer that shows the Top N of a category. So you can for example have the top brands for Apples, Oranges and Blueberries in a slicer, and the sli...
  • danextian's avatar
    1 year ago

    Hi MichaelaMul 

    You can create a numeric range parameter table which column and automatically created measure can be used to filter a rank measure.

    This measure ranks all distinct values in the Model column according to their sales. The ALL function is used applied to the Model column, ensuring that filters from other related columns remain effective.

    Model Rank by Sales = 
    RANKX ( ALL ( 'Product'[Model] ), [Total Sales],, DESC, DENSE )
    

    You can create another measure to returns just the sales of the models which ranks are <= the selected rank value.

    Top N Model Sales = 
    CALCULATE (
        [Total Sales],
        FILTER ( VALUES ( 'Product'[Model] ), [Model Rank by Sales] <= [TopN Value] )
    )
    

    Please see the attached pbix.