cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
aelfering Frequent Visitor
Frequent Visitor

Create a slicer to filter between top and bottom 5?

I have a dataset, and would like to create a slicer so the enduser could select either the "Top 10" or "Bottom 10" of the products. Any ideas?

 

Here is a sample .csv:

PRODUCT,SALES
A,150
B,220
C,200
D,240
E,265
F,290
G,315
H,340
I,365
J,390
K,415
L,440
M,465
N,490
O,515
P,540
Q,565
R,590
S,615
T,640
U,665
V,690
W,715
X,740
Y,765
Z,790
AA,815
BB,840
CC,865
DD,890
EE,915
FF,940
GG,965
HH,990

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User
Super User

Re: Create a slicer to filter between top and bottom 5?

Hi @aelfering ,

 

Create a table with the following data:

ID            Type

1 Bottom 10
2 Top 10

 

Then use the following measure:

 

TOP_N =
VAR raking_asc =
    RANKX (
        ALL ( Sales[SALES]; Sales[PRODUCT] );
        CALCULATE ( SUM ( Sales[SALES] ) )
    )
VAR ranking_desc =
    RANKX (
        ALL ( Sales[SALES]; Sales[PRODUCT] );
        CALCULATE ( SUM ( Sales[SALES] ) );
        ;
        ASC
    )
RETURN
    SWITCH (
        SELECTEDVALUE ( 'Bottom Top Slicer'[ID] );
        1; IF ( ranking_desc <= 10; SUM ( Sales[SALES] ); BLANK () );
        2; IF ( raking_asc <= 10; SUM ( Sales[SALES] ); BLANK () )
    )

If you want to use it on a table with total value this measure needs to be changed.

 

Regards,

MFelix



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

Proud to be a Datanaut!




View solution in original post

1 REPLY 1
Highlighted
Super User
Super User

Re: Create a slicer to filter between top and bottom 5?

Hi @aelfering ,

 

Create a table with the following data:

ID            Type

1 Bottom 10
2 Top 10

 

Then use the following measure:

 

TOP_N =
VAR raking_asc =
    RANKX (
        ALL ( Sales[SALES]; Sales[PRODUCT] );
        CALCULATE ( SUM ( Sales[SALES] ) )
    )
VAR ranking_desc =
    RANKX (
        ALL ( Sales[SALES]; Sales[PRODUCT] );
        CALCULATE ( SUM ( Sales[SALES] ) );
        ;
        ASC
    )
RETURN
    SWITCH (
        SELECTEDVALUE ( 'Bottom Top Slicer'[ID] );
        1; IF ( ranking_desc <= 10; SUM ( Sales[SALES] ); BLANK () );
        2; IF ( raking_asc <= 10; SUM ( Sales[SALES] ); BLANK () )
    )

If you want to use it on a table with total value this measure needs to be changed.

 

Regards,

MFelix



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

Proud to be a Datanaut!




View solution in original post

Helpful resources

Announcements
Can You Solve These Challenge

Challenge: Can You Solve These?

Find out how to participate in the first Power BI 'Can You Solve These?' challenge.

Community News & Announcements

Community News & Announcements

Get your latest community news and announcements.

Virtual Launch Event

Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Community Kudopalooza

Win Power BI Swag with Community Kudopalooza!

Each week, complete activities and be qualified in the drawing for cool Power BI Swag.

Users Online
Currently online: 41 members 1,070 guests
Please welcome our newest community members: