Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Getting bottom 3 dynamicaly

Hi, this one is a bit complicated so i'll try and explain as best as I can. 

I have a table with Order ID, Seller, Ranking of price.

Each order has a different number of rankings. E.g Order 1 might have 6 sellers so would have rankings 1-6.

I would like to calculate the bottom 3 but factor in for orders that have less than 6 rankings. E.g Order 2 has 5 rankings so my measure should only count the bottom 2 as being 'bottom 3'. Order 3 has 4 rankings so my measure should only count the bottom 1 ranking. 

Right now I have a variable that is able to calculate the number of rankings per order:

 

CALCULATE(MAX('Test Table'[Final Ranking]),ALLEXCEPT('Test Table','Test Table'[Order ID]))
//This would return 6 if the order had 6 sellers/rankings.
 
I then made another variable that did the logic for working out bottom 3 which works correctly. E.g when I return this variable and put it in a table visualisation with Order ID and final ranking, it filters for rankings that are in the bottom 3 (which the correct logic above). Here's the code for that variable:
VAR bottom3 = CALCULATE(COUNT('Test Table'[Street Order ID]),FILTER('Test Table',
SWITCH(TRUE,
    numberOfRankings==5,'Test Table'[Final Ranking]>numberOfRankings-2,
    numberOfRankings==4,'Test Table'[Final Ranking]>numberOfRankings-1,
    numberOfRankings>=6,'Test Table'[Final Ranking]>numberOfRankings-3,
    numberOfRankings==3 || numberOfRankings==2 || numberOfRankings==1,0)))
 
Here's a picture showing the measure working:
 
However, when I try to put the measure in a table with seller, it gives me incorrect data. 

My final goal is to have a table with seller and number of orders that the seller ranked in the bottom 3. 

  • Hi Anonymous ,

     

    You could create a new measure based on the "isBottom3".

    _isBottom3 =
    SUMX ( ALLEXCEPT ( Example, Example[Seller] ), [isBottom3] )

    Here is the result.

     

6 Replies