Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
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!
Check out the July 2025 Power BI update to learn about new features.
User | Count |
---|---|
23 | |
9 | |
7 | |
6 | |
6 |
User | Count |
---|---|
28 | |
11 | |
11 | |
10 | |
6 |