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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
jamal29
Regular Visitor

How to Filter Top N with Field Parameters?

Hello Power BI Community,

 

I am using a native table and a field parameter and I want the table to be sorted based on top N when selecting a field parameter. I have tried doing this on Filter pane but it doesn't work. any advice?

Please check the image and DAX below just to help you understand. I want the highlighted columns to be sorted highest to lowest/ Top N when a field parameter is selected.

 

PlayerStats = {
    ("Total Points per player", NAMEOF('0. Measures'[Total Points per player]), 0),
    ("Past 5 GW points", NAMEOF('0. Measures'[Past 5 GW Points per Player]), 1),
    ("Past 3 GW Points", NAMEOF('0. Measures'[Past 3 GW Points]), 2),
    ("Past GW Points", NAMEOF('0. Measures'[Past GW Points]), 3)
}
 

 

FPL.png

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @jamal29 ,

Sorry for being late! If the Past 5 GW points, Past 3 GW points, Total Points per player are currently all measures, it can still be achieved after my test:

vjunyantmsft_0-1710750551499.png

And the measure is like this:

Measure 2 = 
VAR _5 = RANK(DENSE, ALL('Table'), ORDERBY('Table'[_Past 5], DESC))
VAR _3 = RANK(DENSE, ALL('Table'), ORDERBY('Table'[_Past 3], DESC))
VAR _total = RANK(DENSE, ALL('Table'), ORDERBY('Table'[_Total], DESC))
RETURN
IF(
    MAX('Parameter 2'[Parameter]) = "_Past 5",
    IF(
        _5 <= 5,
        1,
        0
    ),
    IF(
        MAX('Parameter 2'[Parameter]) = "_Past 3",
        IF(
            _3 <= 3,
            1,
            0
        ),
        IF(
            MAX('Parameter 2'[Parameter]) = "_Total",
            IF(
                _total <= 10,
                1,
                0
            ),
            1
        )
    )
)

The final output is as below:

vjunyantmsft_1-1710750593748.png
vjunyantmsft_2-1710750599794.png

vjunyantmsft_3-1710750606365.png

 

vjunyantmsft_4-1710750612803.png

vjunyantmsft_5-1710750618870.png

Note: It is on the Page2 in the pbix.


Best Regards,
Dino Tao
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

4 REPLIES 4
Anonymous
Not applicable

Hi @jamal29 ,

If I understand you correctly, you want to implement both the filtering of the field and the filtering of the first N of that column when selecting the parameter. You can try the following method:
Here's the rule I set up: if you choose Total Points per player, you return the entire contents of the column; if you choose Past 5 GW Points, you return the first 5 records in the column from largest to smallest; if you choose Past 3 GW Points, you return the first 3 records in the column from largest to smallest; if you choose Past GW Points, you return the first 10 records in the column from largest to smallest.
I use this DAX to create a new measure:

Measure = 
VAR _5 = RANK(DENSE, ALL('Table'), ORDERBY('Table'[Past 5 GW Points], DESC))
VAR _3 = RANK(DENSE, ALL('Table'), ORDERBY('Table'[Past 3 GW Points], DESC))
VAR _total = RANK(DENSE, ALL('Table'), ORDERBY('Table'[Total Points per player], DESC))
RETURN
IF(
    MAX('Parameter'[Parameter]) = "Past 5 GW Points",
    IF(
        _5 <= 5,
        1,
        0
    ),
    IF(
        MAX('Parameter'[Parameter]) = "Past 3 GW Points",
        IF(
            _3 <= 3,
            1,
            0
        ),
        IF(
            MAX('Parameter'[Parameter]) = "Past GW Points",
            IF(
                _total <= 10,
                1,
                0
            ),
            1
        )
    )
)

Follow the screenshot below to set it up:

vjunyantmsft_0-1710229824620.png

vjunyantmsft_1-1710229847256.png

The final output is as below:

vjunyantmsft_2-1710229880226.png
vjunyantmsft_3-1710229887263.png

vjunyantmsft_4-1710229896556.png

vjunyantmsft_5-1710229917911.png

If you need to realize the data in the table is also arranged from large to small, this can not be achieved using DAX, only you can manually click here to achieve:

vjunyantmsft_6-1710230013854.png

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

Hi Dino,
Really appreciate for your comment here. I can see your measure has variables related to a specific table such as,

VAR _5 = RANK(DENSE, ALL('Table'), ORDERBY('Table'[Past 5 GW Points], DESC))
VAR _3 = RANK(DENSE, ALL('Table'), ORDERBY('Table'[Past 3 GW Points], DESC))
VAR _total = RANK(DENSE, ALL('Table'), ORDERBY('Table'[Total Points per player], DESC))

This is clearly reading from a table. Now I can try and do the way you have done it but i will have to create calculated columns and then follow your approach.
My question is, can I use measures as variables? So the Past 5 GW points, Past 3 GW points, Total Points per player are currently all measures on my project. Looking ahead, I may add some more so understanding the process will be of great benefit.

Thanks.

Anonymous
Not applicable

Hi @jamal29 ,

Sorry for being late! If the Past 5 GW points, Past 3 GW points, Total Points per player are currently all measures, it can still be achieved after my test:

vjunyantmsft_0-1710750551499.png

And the measure is like this:

Measure 2 = 
VAR _5 = RANK(DENSE, ALL('Table'), ORDERBY('Table'[_Past 5], DESC))
VAR _3 = RANK(DENSE, ALL('Table'), ORDERBY('Table'[_Past 3], DESC))
VAR _total = RANK(DENSE, ALL('Table'), ORDERBY('Table'[_Total], DESC))
RETURN
IF(
    MAX('Parameter 2'[Parameter]) = "_Past 5",
    IF(
        _5 <= 5,
        1,
        0
    ),
    IF(
        MAX('Parameter 2'[Parameter]) = "_Past 3",
        IF(
            _3 <= 3,
            1,
            0
        ),
        IF(
            MAX('Parameter 2'[Parameter]) = "_Total",
            IF(
                _total <= 10,
                1,
                0
            ),
            1
        )
    )
)

The final output is as below:

vjunyantmsft_1-1710750593748.png
vjunyantmsft_2-1710750599794.png

vjunyantmsft_3-1710750606365.png

 

vjunyantmsft_4-1710750612803.png

vjunyantmsft_5-1710750618870.png

Note: It is on the Page2 in the pbix.


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

lucadelicio
Super User
Super User

can you post the pbix please?



Luca D'Elicio

LinkedIn Profile

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.