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!




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!




Helpful resources

Announcements
Back to School Contest

Back to School Contest

Engage and empower students with Power BI!

MBAS Gallery

Watch Sessions On Demand!

Continue your learning in our online communities.

Summit Australia 2019

Summit Australia 2019

Travel to Melbourne and network with thousands of peers!

Top Ideas
Users Online
Currently online: 282 members 3,039 guests
Please welcome our newest community members: