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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
nish18_1990
Helper II
Helper II

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
10 REPLIES 10
v-sdhruv
Community Support
Community Support

Hi @nish18_1990 ,
Just wanted to check if you had the opportunity to review the suggestions provided?
If the response has addressed your query, please accept it as a solution  so other members can easily find it.
Thank You

Demert
Resolver II
Resolver II

Hi, Sure. You can find it through the following link:

OneDrive Link 

 

Could you please attach the file as i am unabe to open the one drive due to some restricted permission.

Hi I can't attach the file yet to my replies: try the following we transfer link :

Download 

 

The steps I did:

Create in the modeling view select new parameter and select numeric range. Minimum 1 and max 10 with increments of 1 and add to page.

 

Then create a table visual and drag the subcategory into it. Create a new measure to calculate the total sales and do the ranking based on the total sales

TotalSales = CALCULATE(count('Table'[Sales]),REMOVEFILTERS('Table'[country]))

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

 

Also to check if the selected ranking in the parameter is lower than the rank of the subcategory

 

Nasif_Azam
Solution Sage
Solution Sage

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

I need to do it in Count of sales . My measure is count . How can i calcualte the sum of the total of count of measure . 

Demert
Resolver II
Resolver II

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]))
 

Could you please provide me the power bi .I tried and its not working as expected .

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.