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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Bu__
Frequent Visitor

Filtering a table using TOP N slicer

Hi,

i have a TOP N slicer which is a what if parameter from 0 to 50, i am trying to filter TOP N qty for a product in a table.

please note there is already a TOPN filter on week for the table visual like pic below, so another topn is not possible

Bu___0-1728555480751.png

and the data does not have an id/unique column and the products are repeted several times and the week in the sample is different from the topn loaddateweek.

I am using a DAX measure to calculate the top products

TOP N measure =
VAR SelectedTop = SELECTEDVALUE('TOPN'[TOPN])
RETURN
SWITCH(TRUE(),
    SelectedTop = 0, [Still to supply_sum],
    RANKX(
        ALLSELECTED(table[week],table[Product]),
        [Still to supply_sum], ,DESC,Dense
        ) <= SelectedTop,
    [Still to supply_sum]
)
 
but this is not filtering for only 1 value when top n filter selected =1, but shows multiple value.
Sample data is like below:
WeekProductStill to supply_sumrank
2024 346708587201
2024 407706649191
2024 386708481202
2024 406708430402
2024 38731344003
2024 366708335603
2024 397448360003
2024 416961320405
2024 38300300806
2024 36300281207
2024 307551247209
2024 411221160102216010
2024 367312156011
2024 4175511979015
2024 3275511916817
2024 313001620424
2024 323001566925

Not sure how to solve this issue to just have rank that does not repeat for a another row for the same product.

 

Thanks for the help in advance.

1 ACCEPTED SOLUTION

Hi @Bu__ ,

 

Do you mean that you want to show TopN for each week? I think you can try ALLEXCEPT() function.

rank = 
VAR SelectedTop = SELECTEDVALUE('TOPN'[TOPN])
RETURN
SWITCH(TRUE(),
    SelectedTop = 0, [Still to supply_sum],
    RANKX(
        ALLEXCEPT('Table','Table'[Week]),
        [Still to supply_sum], ,DESC,Dense
        ) <= SelectedTop,
    [Still to supply_sum]
)

Result is as below.

vrzhoumsft_0-1730185913730.png

 

Best Regards,
Rico Zhou

 

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

3 REPLIES 3
v-rzhou-msft
Community Support
Community Support

Hi @Bu__ ,

 

According to your screenshot, I think you add the [Latest load date] to filter the week column. However I couldn't find the logic about [Latest load date].

Here I still have some questions:

1. Is [Still to supply_sum] a measure or a column? 

2. How did you calculate [rank] column? And I couldn't find [TOP N measure] in your statement.

Can you share a sample pbix file with us and show us the result you want? This will make it easier for us to find the solution.

 

Best Regards,
Rico Zhou

 

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

 

 

Hi @v-rzhou-msft ,

 

yes the screenshot shows to filter for the latest week data, here it filters till the latest load date (which will be the max date).

1. yes still to supply is a measure

2.  rank is a measure calculated like below

rank=
VAR SelectedTop = SELECTEDVALUE('TOPN'[TOPN])
RETURN
SWITCH(TRUE(),
    SelectedTop = 0[Still to supply_sum],
    RANKX(
        ALLSELECTED(table[week],table[Product]),
        [Still to supply_sum], ,DESC,Dense
        ) <= SelectedTop,
    [Still to supply_sum]
)
i would like to have something like below:
Bu___0-1728967580842.png

 

when i select top N filter=1 just show 1 product in a week.

Right now the problem is i get top1 product for several weeks when the topn filter=1.

 

 

Hi @Bu__ ,

 

Do you mean that you want to show TopN for each week? I think you can try ALLEXCEPT() function.

rank = 
VAR SelectedTop = SELECTEDVALUE('TOPN'[TOPN])
RETURN
SWITCH(TRUE(),
    SelectedTop = 0, [Still to supply_sum],
    RANKX(
        ALLEXCEPT('Table','Table'[Week]),
        [Still to supply_sum], ,DESC,Dense
        ) <= SelectedTop,
    [Still to supply_sum]
)

Result is as below.

vrzhoumsft_0-1730185913730.png

 

Best Regards,
Rico Zhou

 

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

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.