cancel
Showing results 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.

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:

 Product Rank1 Rank2 Rank Total A1 1 0 4 A5 2 2 2 A3 3 1 1 A4 4 3 3 A2 5 0 5

The Rank Total column shows the result that I need.

How is this possible using DAX?

6 REPLIES 6
Community Support

Hi @joshua1990 ,

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

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.

Super User
Super User

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

Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Post Prodigy

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

Super User

@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?

Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
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] ) ) ``````

Announcements

#### 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

#### Power BI Monthly Update - April 2024

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

#### Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors