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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
joshua1990
Post Prodigy
Post Prodigy

Rank based on two columns

Hi experts!

I know, there have been a lot of posts regarding this, but they have not been useful for me.

The objective is to have a ranking based on two columns.

 

I have a dimension table (Table Dim) that lists all of our products.

Then I have a table (Table Trans) that some transactional values in different columns.

There is the first column called Column1 and another one called Column2.

Now I would like to build a ranking for each product based on Column2 as the first priority and Column1 as the second priority.

Using this DAX Measure I get the ranking for each column:

 

 

Rank1 =
    RANKX ( ALLSELECTED ( 'Table Dim'[Product] ), [Column1] )

 

 

 

 

Rank2 =
    RANKX ( ALLSELECTED ( 'Table Dim'[Product] ), [Column2] )

 

 

 

 

As a result, now I have the following:

ProductRank1Rank2Rank Total
A1104
A5222
A3311
A4433
A250

5

 

The Rank Total column shows the result that I need.

 

How is this possible using DAX?

6 REPLIES 6
v-stephen-msft
Community Support
Community Support

Hi @joshua1990 ,

 

Are your Rank1 and Rank2 calculated columns or measures? There are differences between the two, please refer to

Calculated Columns and Measures in DAX - SQLBI.

 

Please provide some sample data, which will help me create the correct formula.

 

For now, you can refer to this post to try to solve it.

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

AlexisOlson
Super User
Super User

smpa01
Super User
Super User

@joshua1990  the logic for RankTotal is not clear. Please bare more details as to how you arrived there?

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

@smpa01: Thanks for your reply.

First, the Rank Total is based on the numerical value in Rank2. Then all remaining products are based on Rank1.

@joshua1990  do I understand that if Rank2 =1 then that Product is Ranked 1 in Rank Total and rest of the products need to be Ranked again as per Rank1?

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
amitchandak
Super User
Super User

@joshua1990 , Need some data to suggest for column1 and column 2. If they are numbers 

 

Rank1 =
    RANKX ( ALLSELECTED ( 'Table Dim'[Product] ), [Column1]+ [Column2] )


Rank1 =
    RANKX ( ALLSELECTED ( 'Table Dim'[Product] ),calculate( [Column1]+ [Column2] ) ) 
Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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