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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
harshadrokade
Post Partisan
Post Partisan

Top N slicer to be added on dashboard to filter table values

Hi,

 

Thanks for looking into the query.

 

I have a table with date wise values of Sales of the client names. (Client name, Date, Sales)

 

I have created a dax measure as below that gives me YTD numbers as per year selected in Year slicer. Years coming from Master calendar table and that table is connected with Sales table, Date column.

 

1.YTD Net amt =
VAR MaxDate = today()
VAR crrentyear = SELECTEDVALUE('Master Calendar'[year])
RETURN
            CALCULATE(
        SUM('SalesTable'[Net_Amount]),
        MONTH('Master Calendar'[Date]) <= MONTH(today()),
        YEAR('Master Calendar'[Date])=crrentyear )
      
 
I am showing a Table visual on dashboard with Client names and their YTD numbers.
 
I want to add a slicer (with values as Top10 or All) that will show only Top 10 client names (based on max top 10 YTD numbers) if Top10 is selected and shows All clients if All is selected slicer..
 
1 ACCEPTED SOLUTION

Hi @harshadrokade ,

 

Try the following code:

New Ranking = 
SWITCH (
    SELECTEDVALUE ( Slicer_Table[Slicer] ),
    "Top10",
        IF (
           RANKX (
                ALLSELECTED(  SalesTable[Client]),
                CALCULATE([1.YTD Net amt],ALLEXCEPT(SalesTable, SalesTable[Client]))
                ,
                ,
            ) <= 5,
            1
        ),
    1
)

 

File attach.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

18 REPLIES 18
v-yangliu-msft
Community Support
Community Support

Hi  @harshadrokade ,

 

Here are the steps you can follow:

1. Enter data – create a table.

vyangliumsft_0-1697185812489.png

2. Create measure.

Rank =
RANKX(
    ALLSELECTED('SalesTable'),[1.YTD Net amt],,DESC,Dense)
Flag =
var _select=SELECTEDVALUE('Slicer_Table'[Slicer])
return
SWITCH(
    TRUE(),
    _select="Top10" && [Rank]<=10,1,
    _select="All" && [Rank]>=1,1,0)

3. Place [Flag]in Filters, set is=1, apply filter.

vyangliumsft_1-1697185812490.png

4. Result:

Select Top10:

vyangliumsft_2-1697185850048.png

Select All:

vyangliumsft_3-1697185850049.png

 

 

Best Regards,

Liu Yang

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

Thanks @v-yangliu-msft . The slicer is not filtering the table as expected. can you pls check

harshadrokade
Post Partisan
Post Partisan

@MFelix can u pls help here

 

Hi @harshadrokade ,

 

In this case you need to create a table for the disconnected slicer then you need to create a measure that picks up that value something similar to this:

 

Ranking =
SWITCH (
    SELECTEDVALUE ( 'TOPN'[TOPNSelection] ),
    "Top 10",
        IF (
            RANKX (
                ALLSELECTED ( Customer[Customer] ),
                [Sales],
                [Sales],
                DESC
            ) <= 10,
            1
        ),
    1
)

Then use this metric on the visual and select on when is not blank.

MFelix_1-1697186289820.pngMFelix_2-1697186312273.png

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Thanks @MFelix . Ther is no disconnected table. The Sales table and master calendar are connected and so I am not sure how to follow your instructions.

The disconnected table is a new one that you need to create for doing the slicer nothing more. That table only contais two values All and Top 10.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Thanks @MFelix 

 

What do you mean by Then use this metric on the visual and select on when is not blank.

 

Where exactly I use this newly created measure on visual? and what do you mean by when its not blank?

 

Pls help

@harshadrokade

 

Just add it to your visual filter in the filter pane, then the option you select is the advanced is not blank. When you apply that filter the visualization gets filter out. 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



OK. Will try. Thanks

 

If you are not abble to achieve necessary result please let me know and I will send you a PBIX file for test.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Thanks @MFelix. I could get the results partially but facing an issue in the drill downs.

 

I forgot to mention that I have one more column as Sub client name. So I have columns as below in Sales table-

  1. Client name
  2. Sub client name
  3. Date
  4. Sales

A measure is also creaed to get YTD sales as 1.YTD Net amt

 

Sharing steps that I followed-

 

1) Created a disconnected Slicer table with values as Top10 and All

 

2) Created a measure as below to get the rank on Client name level based on YTD numbers

Rank =
RANKX(
    ALL('Sales table'[Client Name]),[1.YTD Net amt],,DESC,Dense)
 
3) Created one more measure that will be used in filter of the column chart
Rank Flag =
var _select=SELECTEDVALUE('Slicer_Table'[Slicer])
return
SWITCH(
    TRUE(),
    _select="Top10" && [xRank]<=10,1,
    _select="All" && [Rank]>=1,1,0)
 
4) Added a column chart visual on dashboard with Client name on X axis, YTD number on Y axis. Added a filter of Rank Flag on visual with value is equal to 1
 
5) Added a slicer visual on dashboard with values from Slicer table.
 
Now the slicer properly filters the chart when I selected Top 10 or All.
 
The problem appears when I add a drilldown of Sub client name to the chart. When I add Sub client name as well to the X axis (Below Client name), the slicer doesnt filter the visual properly.
 
I want the visual to keep showing Top10 Client names even if I drill down to Sub client name on column chart visual but when I add Sub client name to visual for drill down, the visualm starts showing all Client names even if Top10 is selected on slicer.
 
Thanks again for all your help!!

Hi @MFelix - Will you be able to help on this query?

Hi @harshadrokade ,

 

Try the following code:

New Ranking = 
SWITCH (
    SELECTEDVALUE ( Slicer_Table[Slicer] ),
    "Top10",
        IF (
           RANKX (
                ALLSELECTED(  SalesTable[Client]),
                CALCULATE([1.YTD Net amt],ALLEXCEPT(SalesTable, SalesTable[Client]))
                ,
                ,
            ) <= 5,
            1
        ),
    1
)

 

File attach.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



All works fine when I remove my existing relationship between Sales table and master calendar table but when I keep it, the top 10 filter doesnt work. I cant remove it as it filters few other charts on dashboard.

I have used the file you have sent that did not had any relationship so I did not even made any change to that part of the formula, try to chenge your YTD to the following:

 

1.YTD Net amt = 

    TOTALYTD(SUM([Net_Amount]), 'Master Calendar'[Date])

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



U r awesome. Thanks for ur valuable time and support 🙂

@MFelix waiting for ut help 🙂

harshadrokade
Post Partisan
Post Partisan

Hi  v-rongtiep-msft, Can u pls here here

 

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

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