Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

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:
 ranking.png
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. 

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

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

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

Here is the result.

1-1.PNG

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

6 REPLIES 6
v-eachen-msft
Community Support
Community Support

Hi @Anonymous ,

 

Could you please share your sample data and excepted result to me if you don't have any Confidential Information? Please upload your files to OneDrive and share the link here.

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.
Anonymous
Not applicable

@Greg_Deckler @v-eachen-msft https://1drv.ms/u/s!AmSmgu3y1hya6Hs21_KKtUPVBeXM?e=NAk0qA - sample file.

 

The expected output is described above. Thank you

Hi @Anonymous ,

 

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

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

Here is the result.

1-1.PNG

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.
Anonymous
Not applicable

Great! That worked! Thank you very much

Greg_Deckler
Super User
Super User

Sample data please. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.