Forum Discussion
Top N as a dynamic filter
- 8 years ago
Hi Anonymous,
1. Create a table like below. Do not establish relationship with other tables.
Rule ID
top 1 - 10 1 top 10 - 20 2 top 20 - 30 3 2. Create a measure like below.
rankColorName = VAR rankShouldBe = RANKX ( ALL ( DimProduct[ProductName] ), CALCULATE ( SUM ( FactSales[SalesQuantity] ) ) ) RETURN IF ( HASONEFILTER ( ruleTable[Rule] ), IF ( MIN ( ruleTable[ID] ) = 1 && rankShouldBe <= 10, rankShouldBe, IF ( MIN ( ruleTable[ID] ) = 2 && rankShouldBe > 10 && rankShouldBe <= 20, rankShouldBe, IF ( MIN ( ruleTable[ID] ) = 3 && rankShouldBe > 20 && rankShouldBe <= 30, rankShouldBe, BLANK () ) ) ), rankShouldBe )3. Create a table visual and a slicer like below.
Best Regards,
Dale
Hi Anonymous,
1. Create a table like below. Do not establish relationship with other tables.
Rule ID
| top 1 - 10 | 1 |
| top 10 - 20 | 2 |
| top 20 - 30 | 3 |
2. Create a measure like below.
rankColorName =
VAR rankShouldBe =
RANKX (
ALL ( DimProduct[ProductName] ),
CALCULATE ( SUM ( FactSales[SalesQuantity] ) )
)
RETURN
IF (
HASONEFILTER ( ruleTable[Rule] ),
IF (
MIN ( ruleTable[ID] ) = 1
&& rankShouldBe <= 10,
rankShouldBe,
IF (
MIN ( ruleTable[ID] ) = 2
&& rankShouldBe > 10
&& rankShouldBe <= 20,
rankShouldBe,
IF (
MIN ( ruleTable[ID] ) = 3
&& rankShouldBe > 20
&& rankShouldBe <= 30,
rankShouldBe,
BLANK ()
)
)
),
rankShouldBe
)
3. Create a table visual and a slicer like below.
Best Regards,
Dale
- Anonymous8 years agoNot applicable
Hi v-jiascu-msft,
I'am facing an issue
The moment I bring in a new column in the table, the filter does not fuction and it shows all products.
What could be the reason?
- v-jiascu-msft8 years agoMicrosoft Employee
Hi Anonymous,
Where is the column from? Maybe you can make some changes like below.
rankColorName = VAR rankShouldBe = RANKX ( ALL ( DimProduct[ProductName] ), CALCULATE ( SUM ( FactSales[SalesQuantity] ), ALLEXCEPT(DimProduct, DimProduct[Product Name] ) ) ) RETURN IF ( HASONEFILTER ( ruleTable[Rule] ), IF ( MIN ( ruleTable[ID] ) = 1 && rankShouldBe <= 10, rankShouldBe, IF ( MIN ( ruleTable[ID] ) = 2 && rankShouldBe > 10 && rankShouldBe <= 20, rankShouldBe, IF ( MIN ( ruleTable[ID] ) = 3 && rankShouldBe > 20 && rankShouldBe <= 30, rankShouldBe, BLANK () ) ) ), rankShouldBe )Best Regards,
Dale
- Anonymous8 years agoNot applicable
The ALLExcept function did not work for me.
The columns: Product name and Sales quantity are coming from the same table. And the column that I'am trying to get in the table is from another table. But the problem seems to occur even if I bring the any other column from the same table.
What could be the possible reason, any idea?
- Anonymous6 years agoNot applicable
I have a similar situation. i tried this method. It does work. However, i cant get it to closure since i dont want to show the "rankcolorName" in the view.
How can i achieve it?