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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Kolumam
Post Prodigy
Post Prodigy

How to rank based on 2 columns?

Hi All,

 

I need to rank the table based on 2 columns. Here is the table.

 

NameProbabilityQuantityClose Date
Tesla20%101/9/2020
Honda50%101/8/2020
Maruti50%101/7/2020

 

In my above table, first it needs to be ranked by probability * quanitity.

If probability * quantity is same for two rows, it needs to be ranked by the Close Date. So the earlier the close date, the higher the ranking.

 

Expected Output:

 

NameProbabilityQuantityClose DateRanking
Tesla20%101/9/20203
Honda50%101/8/20202
Maruti50%101/7/20201

 

Is it possible?

 

2 ACCEPTED SOLUTIONS
mahoneypat
Microsoft Employee
Microsoft Employee

Please try this expression.  I put your data in and called the table 'Make'.  It works by also adding in the days between today and the close date (divided by a large number so it doesn't affect the overall rank, but does break the tie).  Based on your values, you can increase the divided by number.

 

Rank with Date =
RANKX (
ALL ( Make ),
CALCULATE ( SUMX ( Make, Make[Quantity] * Make[Probability] ) )
+ DATEDIFF ( CALCULATE ( MIN ( Make[Close Date] ) ), TODAY (), DAY ) / 1000
)

 

If this works for you, please mark it as solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

az38
Community Champion
Community Champion

@Kolumam 

try a measure

Measure = RANKX(
ALLSELECTED('Table'), 
CALCULATE(
SUMX('Table','Table'[Probability]*'Table'[Quantity] + (10000 - INT('Table'[Close Date])/10000))
),
 , DESC)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

6 REPLIES 6
mahoneypat
Microsoft Employee
Microsoft Employee

Please try this expression.  I put your data in and called the table 'Make'.  It works by also adding in the days between today and the close date (divided by a large number so it doesn't affect the overall rank, but does break the tie).  Based on your values, you can increase the divided by number.

 

Rank with Date =
RANKX (
ALL ( Make ),
CALCULATE ( SUMX ( Make, Make[Quantity] * Make[Probability] ) )
+ DATEDIFF ( CALCULATE ( MIN ( Make[Close Date] ) ), TODAY (), DAY ) / 1000
)

 

If this works for you, please mark it as solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


az38
Community Champion
Community Champion

Hi @Kolumam 

try technique from this great article https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns

 

Column = RANKX('Table', [Probability]*[Quantity] + (10000 - INT([Close Date])/10000), , DESC)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Thank you so much. It kinda worked!

 

The issue now is how do I add a country filter from Country table?

 

See the below screenshot. If I filter a country, the ranking get's lost and it doesn't start from 1.

 

unknown.png

Try changing the ALL() to an ALLSELECTED() so it responds to the slicers.

 

If this works for you, please mark it as solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Thanks mate! It worked. If I have any issues will get back to you.

az38
Community Champion
Community Champion

@Kolumam 

try a measure

Measure = RANKX(
ALLSELECTED('Table'), 
CALCULATE(
SUMX('Table','Table'[Probability]*'Table'[Quantity] + (10000 - INT('Table'[Close Date])/10000))
),
 , DESC)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.