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
Alex_192
Frequent Visitor

Rank with 3 conditions

Hello Everyone,

 

I would like to look at my top 2 product per client per country.

To do that I have created a new table (see example below) with the information I need.

 

I would like to know if you could help me with the DAX formula to have the column rank 2016 & rank 2017 (which is for me a rankx based on 3 criteria: country, client and product name according to either 2016 sales or 2017 sales) ?

CountryClientProduct name2016 sales2017 salesRank 2016Rank 2017Final Rank 2016Final Rank 2017
ItalyITA_1A1005012Top 2Top 2
ItalyITA_1B5010021Top 2Top 2
ItalyITA_1C252533OthersOthers
ItalyITA_2A2005014Top 2Others
ItalyITA_2B15020022Top 2Top 2
ItalyITA_2C7515033OthersOthers
ItalyITA_2D5030041OthersTop 2
GermanyGER_1A305011Top 2Top 2
GermanyGER_1B204022Top 2Top 2
GermanyGER_1C101033OthersOthers
GermanyGER_2A40030012Top 2Top 2
GermanyGER_2B35020023Top 2Others
GermanyGER_2C10050031OthersTop 2

 

Thanks in advance,

 

Alex

1 ACCEPTED SOLUTION
v-ljerr-msft
Employee
Employee

Hi @Alex_192,

 

Based on my test, you should be able to use the formulas below to create new calculate column in this scenario. Smiley Happy

 

Rank 2016 =
RANKX (
    FILTER (
        ALL ( Table1 ),
        Table1[Country] = EARLIER ( Table1[Country] )
            && Table1[Client] = EARLIER ( Table1[Client] )
    ),
    Table1[2016 sales]
)
Rank 2017 = 
RANKX (
    FILTER (
        ALL ( Table1 ),
        Table1[Country] = EARLIER ( Table1[Country] )
            && Table1[Client] = EARLIER ( Table1[Client] )
    ),
    Table1[2017 sales]
)

Note: Just replace 'Table1' with your real table name.

 

 

c2.PNG

 

Regards

View solution in original post

2 REPLIES 2
v-ljerr-msft
Employee
Employee

Hi @Alex_192,

 

Based on my test, you should be able to use the formulas below to create new calculate column in this scenario. Smiley Happy

 

Rank 2016 =
RANKX (
    FILTER (
        ALL ( Table1 ),
        Table1[Country] = EARLIER ( Table1[Country] )
            && Table1[Client] = EARLIER ( Table1[Client] )
    ),
    Table1[2016 sales]
)
Rank 2017 = 
RANKX (
    FILTER (
        ALL ( Table1 ),
        Table1[Country] = EARLIER ( Table1[Country] )
            && Table1[Client] = EARLIER ( Table1[Client] )
    ),
    Table1[2017 sales]
)

Note: Just replace 'Table1' with your real table name.

 

 

c2.PNG

 

Regards

Hi v-ljerr-msft,

 

Thank you for your help !!

 

It's working 🙂

 

Best,

 

Alex

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.