Forum Discussion
Implementing a TopN filter per category
Please try
Sales Top 20 Products =
IF (
NOT ISEMPTY (
INTERSECT (
VALUES ( 'Product'[Product Name] ),
TOPN (
20,
CALCULATETABLE ( VALUES ( 'Product'[Product Name] ), ALL ( 'Product' ) ),
[Total Sales]
)
)
),
[Total Sales]
)
Hi tamerj!
This seems to be working, massive thanks!
If it's not too much trouble, could you explain the logic of it?
I get that it's a intersect of the top 20 product sales table and the all products table, but not sure what's the NOT ISEMPTY do?
Thank you,
B
- tamerj13 years agoCommunity Champion
Sales Top 20 Products = IF ( NOT ISEMPTY ( INTERSECT ( VALUES ( 'Product'[Product Name] ), TOPN ( 20, CALCULATETABLE ( VALUES ( 'Product'[Product Name] ), ALL ( 'Product' ) ), [Total Sales] ) ) ), [Total Sales] )The intersection is between the products that are avialable in the current filter context and the top 20 products. If the the result of this intersection is NOT an empty table (the current product is one of the top 20 products) then the measure is calculated otherwise a blank will be returned.