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

create rank column based on column using dax

Greetings !!

 

I have a region slicer which drop downs as Test1, Test2 , Test3. And a Rank slicer which has ranges and occurs based on the Rank column.

 

i have data set given below .

RegionProjectNameText ValueRankExpected RNK
Test1wewqe5.0011
Test1yuy5.0011
Test2ty20.3521
Test3ert48.7331
Test3ertrre78.3942
Test3sdada78.3942
     

 

The above calculation for Rank column is if text value is same, rank is same and increases on next values irrespective of region column .

 

I am in need of help in creating rank column (Expected RNK) as shown above. ie based on both the text value and region column.

 

If test 2 is selected in Region slicer and Rank slicer is set to 1, then i need result as given below .

 

RegionProjectNameText ValueRankExpected RNK
Test2ty20.3521

 

Please help me out.

1 ACCEPTED SOLUTION
LivioLanzo
Solution Sage
Solution Sage

You can create the column like this:

 

Column = 
VAR CurVal = [Text Value]
RETURN
CALCULATE(
    RANKX( Data, [Text Value], CurVal, ASC, Dense ),
    ALLEXCEPT( Data, Data[Region] )
)

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

View solution in original post

4 REPLIES 4
LivioLanzo
Solution Sage
Solution Sage

You can create the column like this:

 

Column = 
VAR CurVal = [Text Value]
RETURN
CALCULATE(
    RANKX( Data, [Text Value], CurVal, ASC, Dense ),
    ALLEXCEPT( Data, Data[Region] )
)

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

You - from 4 years ago I guess - saved me a ton of time.  I was trying to do a filter and trying to do something with the transform data - I needed to find the top 5 values for each hour and this plus a filter of >=5 on my new column was what I needed - thanks!

@LivioLanzo  Thanks for your help!! but i am stuck with the calculation

 

I have created a column as you has specified with ranking order to be desc as given below.

Column = 
VAR CurVal = [Text Value]
RETURN
CALCULATE(
    RANKX( Data, [Text Value], CurVal, Desc, Dense ),
    ALLEXCEPT( Data, Data[Region] )
)

 

For the dataset given below, calculated column is working as shown .

 

RegionProjectNameText ValueExpected RNK
Test1wewqe5.001
Test1yuy5.001
Test2ty20.351
Test2ty5.002
Test3wewrt48.733
Test3frtrre78.392
Test3sdada5.001

 

For the Region "Test3" , rank is calculated wrongly as shown above.

 

Rank should be calculated as

Test3wewrt48.732
Test3frtrre78.391
Test3sdada5.003

 

Kindly do needful.

Hi @Dharini

 

If you wish the rank to happen the other way around, you just need to change this argument of the RANKX function:

 

RANKX( Data, [Text Value], CurVal, ASC, Dense )

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

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.