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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
tim_m15
Resolver I
Resolver I

Filter one table top 10 rows by value based on slicer

Hello dear community,

First I explain my starting position and then the goal I have.

I have created a new table in the dataset (screenshot 1 at the bottom of this post), which will serve me as a slicer in the report in single select selection controls with the function to dynamically filter my one and only table depending on the selection (screenshot 2 at the bottom of this post).

Furthermore there is a Measure "Filter Dashboard" (Code-Example below), which selects each of the Values (Whole, Top 10, Bottom 10) with a SELECTEDVALUE-Function. I put this measure as a filter on the one and only table in the report and say "Filter Dashboard is 1" to make it active.

You can see my approach how I created the "Filter Dashboard" measure in this Code-Example:

 

 

 

 

 

Filter Dashboard = 

IF (
    SELECTEDVALUE ('Filter-Table'[Value] ) = "Whole",
    1,

IF (
    SELECTEDVALUE ( 'Filter-Table'[Value]) = "Top 10",
    TOPN(10,'Bookings-Table',[Turnover-Measure],DESC)

IF (
    SELECTEDVALUE ( 'Filter-Table'[Value]) = "Bottom 10",
   TOPN(10,'Bookings-Table',[Turnover-Measure],ASC)
))))

 

 

 

 

 

My goal is to filter my table only in the two cases top 10 or bottom 10 that I select in single select selection controls in my Slicer. 

But unfortunately it does not work, what I am doing wrong?

Thank you for your support, I look forward to your answers.
Best Regards
Tim

Screenshot 1Screenshot 1Screenshot 2Screenshot 2

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @tim_m15 ,

 

Your coding seems ok, however believe that the best approach is to use the RANKX measure.

 

I would use a combination between switch and the rankx see below:

 

Filtering =
VAR Ranking_Asc =
    RANKX ( ALLSELECTED ( 'Table' ), CALCULATE ( [Total value] ),, ASC )
VAR Ranking_Desc =
    RANKX ( ALLSELECTED ( 'Table' ), CALCULATE ( [Total value] ),, DESC )
RETURN
    SWITCH (
        SELECTEDVALUE ( 'Filter-Table'[ID] ),
        1, 1,
        2, IF ( Ranking_Asc <= 10, 1 ),
        3, IF ( Ranking_Desc <= 10, 1 )
    )

 

 

Now just filter all 1 on your visualization:

Sorting_Hide.gif

 

 

Be aware the since my table is small I'm using the entire table on the ALLSELECTED you may need to adjust this to just some columns or to a summarized version of your table in order to have the expected result.

 

This is just one alternative there are others that can use TOPN, but belive this can make what you need.

 

Check PBIX 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

2 REPLIES 2
MFelix
Super User
Super User

Hi @tim_m15 ,

 

Your coding seems ok, however believe that the best approach is to use the RANKX measure.

 

I would use a combination between switch and the rankx see below:

 

Filtering =
VAR Ranking_Asc =
    RANKX ( ALLSELECTED ( 'Table' ), CALCULATE ( [Total value] ),, ASC )
VAR Ranking_Desc =
    RANKX ( ALLSELECTED ( 'Table' ), CALCULATE ( [Total value] ),, DESC )
RETURN
    SWITCH (
        SELECTEDVALUE ( 'Filter-Table'[ID] ),
        1, 1,
        2, IF ( Ranking_Asc <= 10, 1 ),
        3, IF ( Ranking_Desc <= 10, 1 )
    )

 

 

Now just filter all 1 on your visualization:

Sorting_Hide.gif

 

 

Be aware the since my table is small I'm using the entire table on the ALLSELECTED you may need to adjust this to just some columns or to a summarized version of your table in order to have the expected result.

 

This is just one alternative there are others that can use TOPN, but belive this can make what you need.

 

Check PBIX 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



Hi Miguel, 

thank you for your detailed answer and for the sample file. Your solutions works fine!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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