Forum Discussion

MarieAmell's avatar
MarieAmell
Frequent Visitor
3 years ago
Solved

TopN Slicer with legends

Hi All,

 

I'd like to add a slicer to display the top 5, 10, 20 or All of my advertisers.

 

  • I have created a table "TopN_Value" as follow :

 

  • Then, I created the measure :
_Top N Adv = CALCULATE([_Spends (€)], TOPN(TopN_Value[Valeur N_value], ALL('Data'[Advertiser]), [_Spends (€)]), values('Data'[Advertiser]))

 

  • It works when I have only spends by advertisers :

 

 

  • But when I want to add a legend, it doesn't work anymore :
 

 

 

If someone could explain to me what's wrong and how I can correct that, it would be awesome !

 

Thanks a lot

  • MarieAmell , when use legend with TOPN , that will topN Inside that legend.

     

    Use a visual level filter of TOPN

     

    or

    Try measures like

     

    _Top N Adv = sumx(keepfilters( TOPN(TopN_Value[Valeur N_value], ALL('Data'[Advertiser],'Data'[legend column] ), [_Spends (€)])), [_Spends (€)])

     

     

    _Top N Adv = sumx(keepfilters( TOPN(TopN_Value[Valeur N_value], ALL('Data'[Advertiser] ), calculate([_Spends (€)], removefilters('Data'[legend column])) )), [_Spends (€)])

2 Replies

  • MarieAmell , when use legend with TOPN , that will topN Inside that legend.

     

    Use a visual level filter of TOPN

     

    or

    Try measures like

     

    _Top N Adv = sumx(keepfilters( TOPN(TopN_Value[Valeur N_value], ALL('Data'[Advertiser],'Data'[legend column] ), [_Spends (€)])), [_Spends (€)])

     

     

    _Top N Adv = sumx(keepfilters( TOPN(TopN_Value[Valeur N_value], ALL('Data'[Advertiser] ), calculate([_Spends (€)], removefilters('Data'[legend column])) )), [_Spends (€)])

  • MarieAmell's avatar
    MarieAmell
    Frequent Visitor

    Hi amitchandak , thanks a lot for your help !

    The 2nd measure you proposed works.

    Thanks again, have a nice day