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
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
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!