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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Top N as a dynamic filter

Hello all,

 

I want to create a slicer for top N products by sales. I need a filter which has values:

1) top1-10

2) top 10-20

3) top 20-30

 

Whenever the user clicks on any of the three the products get filtered by sales values and are displayed.

Can this be done? If not, anything similar to this is also most welcome.

1 ACCEPTED SOLUTION
v-jiascu-msft
Microsoft Employee
Microsoft Employee

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.

Top_N_as_a_dynamic_filter

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

8 REPLIES 8
v-jiascu-msft
Microsoft Employee
Microsoft Employee

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.

Top_N_as_a_dynamic_filter

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not 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?

Anonymous
Not 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?

 

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

 

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi @v-jiascu-msft

 

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?

Hi @Anonymous,

 

Can you share your file and the result you want? Please mask the private parts first. A dummy one will be great.

 

Best Regards,

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hey @v-jiascu-msft

 

I tried the method where we create a "what if" parameter for top N filter. I'am able to solve the problem partially. I will get back to you if I need help. Thanks for all the help.

Pulkit
Resolver I
Resolver I

You can use RANKX and bookmarks to achieve this. 
Create the visual, then in the visual level filter do the basic filtering to select only the ranks 1-10 (I am assuming you will give 1st rank to the highest sales), then bookmark it. Do the same for TOP N = 11-20 and 21-30.

After creating the three bookmarks add them to buttons. This is not filter but it will do the the job.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors