Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hi !
I would like to visualy keep in my table (table as a visualization, not in terms of data source) only n first rows based on the value of a metric column for a category.
Exemple : in the below table, I would like to display only the 2 most sold product id in the category A and the 2 most sold in the category B. So I will visualy have only 4 rows in my table.
How would you do that ?
Thanks 😉
| product id | category 1 | category 2 | sales |
FDFSDF | A | X | 543554 |
| HFGHFGH | B | X | 34234 |
| YRTYY | A | Y | 7567 |
| ERERZR | A | X | 234 |
| gDFGDG | B | Y | 23434 |
| GFDGDFG | A | Y | 5345345 |
| JHGF | A | Y | 4324 |
| qFGD | B | Y | 543354 |
| gdFGG | B | X | 5345345 |
Solved! Go to Solution.
Here is a measure that seems to work. Just replace Top2 with your actual table name.
Top 2 AB =
VAR top2x =
TOPN (
2,
ADDCOLUMNS (
ALLSELECTED ( Top2[product id] ),
"cSales", CALCULATE ( SUM ( Top2[sales] ), ALL ( Top2[category 1] ) )
),
[cSales], DESC
)
VAR result =
CALCULATE ( SUM ( Top2[sales] ), KEEPFILTERS ( top2x ) )
RETURN
result
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
Here is a measure that seems to work. Just replace Top2 with your actual table name.
Top 2 AB =
VAR top2x =
TOPN (
2,
ADDCOLUMNS (
ALLSELECTED ( Top2[product id] ),
"cSales", CALCULATE ( SUM ( Top2[sales] ), ALL ( Top2[category 1] ) )
),
[cSales], DESC
)
VAR result =
CALCULATE ( SUM ( Top2[sales] ), KEEPFILTERS ( top2x ) )
RETURN
result
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
Hi,
Thanks for your answer @ValtteriN ! The problem is that I have 150 categories so it will be very long for me to create one formula for each category.
Hi,
You can create a filter measure like this:
I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!
Proud to be a Super User!
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
Check out the November 2025 Power BI update to learn about new features.
| User | Count |
|---|---|
| 19 | |
| 10 | |
| 9 | |
| 4 | |
| 4 |
| User | Count |
|---|---|
| 34 | |
| 32 | |
| 20 | |
| 12 | |
| 11 |