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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
donnie17
Regular Visitor

How to create a dynamic top N for a matrix with multiple values

Hi eveyone,
I was wondering if there was any chance to have a way more dynamic Top N slicer.
As you can see, if I select 2, I do see top 2 Sales but i alse all the lines of COGS

donnie17_0-1729633429631.png

Is it possible to have the same number of lines for COGS (in this case) as there are for Total Sales? For example, if I select 3, only 3 rows should appear, and so on.

Here DAX for TotalSales

TotalSales =
VAR vSegmentRanking = RANKX(ALLSELECTED(financials[Segment]),[Sales],,DESC,Dense)
VAR vCountryRanking = RANKX(ALLSELECTED(financials[Country]),[Sales],,DESC,Dense)

VAR vResults =
    SWITCH(
        TRUE(),
                ISINSCOPE(financials[Segment]),vSegmentRanking,
                ISINSCOPE(financials[Country]),vCountryRanking
    )
RETURN
        IF(vResults <= DynamicRank[Valore DynamicRank], [Sales])



2 ACCEPTED SOLUTIONS
Ritaf1983
Super User
Super User

Hi @donnie17 
Yes, you can achieve it.
As a first step create a parameters table for selecting Top n 

Ritaf1983_0-1729650641216.png

Ritaf1983_1-1729650676686.png

And the 2 measures according to yours, like in my case:

1.

TopN country profits =
VAR SelectedTop = SELECTEDVALUE('Top n'[Top n])
RETURN
SWITCH(TRUE(),
    SelectedTop = 0, [total profits (K/$)],
    RANKX (
            ALLSELECTED(  'Customers'[Country] ),
            [Total sales (K/$)]
                )
                  <= SelectedTop,
        [total profits (K/$)]
)
2. 
TopN country sales =
VAR SelectedTop = SELECTEDVALUE('Top n'[Top n])
RETURN
SWITCH(TRUE(),
    SelectedTop = 0, [total_sales],
    RANKX (
            ALLSELECTED(  'Customers'[Country] ),
            [Total sales (K/$)]
                )
                  <= SelectedTop,
        [Total sales (K/$)]
)
Result :
Ritaf1983_2-1729650814551.png

The pbix is attached

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

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

View solution in original post

shafiz_p
Super User
Super User

Hi @donnie17  You already done all the work. You just need to do a small thing.  Select the matrix visual, go to filter pane, Select Total Sales and set to "Is not blank", Click apply. You are done.

 

I have tried to implement your scenario. See images:

No filter applied:

shafiz_p_0-1729658415135.png

After applied filter:

shafiz_p_1-1729658809853.png

 

 

Hope this helps!!

If this solved your problem, please accept it as a solution!!

 

 

Best Regards,
Shahariar Hafiz

View solution in original post

3 REPLIES 3
shafiz_p
Super User
Super User

Hi @donnie17  You already done all the work. You just need to do a small thing.  Select the matrix visual, go to filter pane, Select Total Sales and set to "Is not blank", Click apply. You are done.

 

I have tried to implement your scenario. See images:

No filter applied:

shafiz_p_0-1729658415135.png

After applied filter:

shafiz_p_1-1729658809853.png

 

 

Hope this helps!!

If this solved your problem, please accept it as a solution!!

 

 

Best Regards,
Shahariar Hafiz

Ritaf1983
Super User
Super User

Hi @donnie17 
Yes, you can achieve it.
As a first step create a parameters table for selecting Top n 

Ritaf1983_0-1729650641216.png

Ritaf1983_1-1729650676686.png

And the 2 measures according to yours, like in my case:

1.

TopN country profits =
VAR SelectedTop = SELECTEDVALUE('Top n'[Top n])
RETURN
SWITCH(TRUE(),
    SelectedTop = 0, [total profits (K/$)],
    RANKX (
            ALLSELECTED(  'Customers'[Country] ),
            [Total sales (K/$)]
                )
                  <= SelectedTop,
        [total profits (K/$)]
)
2. 
TopN country sales =
VAR SelectedTop = SELECTEDVALUE('Top n'[Top n])
RETURN
SWITCH(TRUE(),
    SelectedTop = 0, [total_sales],
    RANKX (
            ALLSELECTED(  'Customers'[Country] ),
            [Total sales (K/$)]
                )
                  <= SelectedTop,
        [Total sales (K/$)]
)
Result :
Ritaf1983_2-1729650814551.png

The pbix is attached

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

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile
ghoshabhijeet
Solution Supplier
Solution Supplier

@donnie17Thank you for sharing your query. Could you please share the pbix file with some sample data ?

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.