Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
nish18_1990
Helper I
Helper I

Top N parameter based on the totals in matrix

Hi ,

 

I need a top N parameter based on the count of Sales .  If i select top 2 then it should show me top 2 subcategory based on the total Sales which is displayed on the right side .

 

nish18_1990_1-1750425500473.png

 

 

Data:

 

CategorySub CategorySalesQuantity Q2country
FurnitureChairs10010China
FurnitureTables10020China
AutomobileCars10030China
AutomobileBikes70040China
FurnitureChairs10013India
FurnitureTables50022India
AutomobileCars10054India
AutomobileBikes10060India
FurnitureChairs10030China
FurnitureTables30029China
AutomobileCars20088China
AutomobileBikes10022China
FurnitureChairs50021India
FurnitureTables10033India
AutomobileCars60054India
AutomobileBikes10060India
FurnitureChairs10030China
FurnitureTables10029China
FurnitureSofa10088China
FurnitureBed10022China
FurnitureDining10021India
FurnitureTables10033India
FurnitureTables10054India
FurnitureSofa10060India
AutomobileCars100054India
AutomobileBikes10060India
FurnitureChairs10030China
FurnitureTables20029China
FurnitureSofa10088China
FurnitureBed10022China
FurnitureDining10021India
FurnitureTables40033India
FurnitureTables80054India
FurnitureSofa10060India
4 REPLIES 4
Nasif_Azam
Impactful Individual
Impactful Individual

Hey @nish18_1990 ,

To implement a Top N parameter based on the total sales in your matrix, you can follow these steps:

 

  1. Create a Measure for Total Sales: Create a DAX measure to sum up the Sales column for each subcategory. 

    TotalSales = SUM('YourTable'[Sales])
  2. Create a Top N Filter Using DAX: You can create a dynamic measure that calculates the rank of each subcategory based on TotalSales and then filters to show only the Top N subcategories. 

    RankBySales = RANKX(ALL('YourTable'[Sub Category]), [TotalSales], , DESC, Dense)

    This RankBySales measure will rank the subcategories based on total sales in descending order. The Dense argument ensures that if multiple subcategories have the same total sales, they will get the same rank.

  3. Apply the Top N Filter: To apply a Top N filter, create a slicer allowing users to select the number of subcategories they want to view (e.g., Top 2). Then, add the RankBySales measure to the Filters on this visual pane in the matrix. Set the filter condition to show subcategories where the RankBySales measure is less than or equal to the selected Top N value.

For Detailed Information:

RANKX Function in DAX

Using Power BI Slicers

 

 

If you found this solution helpful, please consider accepting it and giving it a kudos (Like) it’s greatly appreciated and helps others find the solution more easily.


Best Regards,
Nasif Azam

Demert
Frequent Visitor

Hi

you can create a new measure Called TotalSales with the following code: 

CALCULATE(count('Table'[Sales]),REMOVEFILTERS('Table'[country]))
and change 'Table" to your table name. This will calculate the total of all the sales by removing the filter of countries that is automatically applied by the matrix visual. Next up you can drag this measure into your Filter pane view and filter the Sub category
 Demert_0-1750426473040.png

 

I need a dynamic parameter selection for Top N selection as well. 

Hi,

 

What you can do is add a numeric field parameter as input fro your dynamic parameter selection. After that you need to create a new measure to calculate the ranking. And determine if the ranking is above or under the selected Top N.

 

Here is an example: 

 

RankBySales =
VAR _SelectedRank = SELECTEDVALUE(Parameter[Parameter])
VAR _Ranking = RANKX(ALL('Table'[Sub Category]), [TotalSales], , DESC,Skip)
RETURN IF( _Ranking > _SelectedRank , BLANK(),COUNT('Table'[Sales]))
 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.