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
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] ) ) 

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.

Top Solution Authors