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
Anonymous
Not applicable

Rankx = struggling with duplicates values

Hi,

 

I looked a dozen of posts and webpages about how to create a rank with DAX, but I can't find the solution.

 

https://app.powerbi.com/groups/me/reports/e5ac9c36-b492-460a-974a-168797870f7d?ctid=2af43e5d-907a-49...

 

here is a simple example :

 

I have a dataset with some projects and some duplicates with the Details_Project column

 

ID_PROJECTPROJECT_NAMEDUE_TOSTATUSAREADISTANCEDETAILS_PROJECT
207492Project A31/12/2032In progress1800006649detail 1
155362Project AA30/06/2012Finished450008161detail 1
155362Project AA30/06/2012Finished450008161detail 2
126827Project B31/12/2019In progress35170478detail 1
126827Project B31/12/2019In progress35170478detail 2
126827Project B31/12/2019In progress35170478detail 3
126827Project B31/12/2019In progress35170478detail 4
126827Project B31/12/2019In progress35170478detail 5

 

I want to create a visualization for status projects "Finished" and get a rank based on distance or area (user has to choice with a segment)

 

I created 2 measures, but the ranks are not working properly because of the duplicates I think.

I maybe have to combine Rankx with Summarize ?

 

Please, could you check my test online ?

 

Thanks a lot !

 

 

 

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

I found the solution by using SUMMARIZE !

 

so if in your dataset you have some duplicates, but you want to rank on a unique row you can use :

 

RankingAREA_Summarize_2 = 
RANKX(
    ALLSELECTED('Rank Exercice');
    CALCULATE(sumx(SUMMARIZE('Rank Exercice';'Rank Exercice'[ID_PROJECT];'Rank Exercice'[AREA]);'Rank Exercice'[AREA]));;DESC;Dense
    )

In my case, I wanted to rank by AREA 

 

same thing to order by DISTANCE.

 

And in case, if you want your users to select via a segment which rank to display, just use :

 

RankingCHOICE = 
VAR Unit = SELECTEDVALUE(USER_CHOICE[LIB])
RETURN

SWITCH(TRue();
    Unit = "distance";'DAX_MESURES'[RankingDISTANCE_Summarize_2];
    Unit = "area";'DAX_MESURES'[RankingAREA_Summarize_2])

 

View solution in original post

1 REPLY 1
Anonymous
Not applicable

I found the solution by using SUMMARIZE !

 

so if in your dataset you have some duplicates, but you want to rank on a unique row you can use :

 

RankingAREA_Summarize_2 = 
RANKX(
    ALLSELECTED('Rank Exercice');
    CALCULATE(sumx(SUMMARIZE('Rank Exercice';'Rank Exercice'[ID_PROJECT];'Rank Exercice'[AREA]);'Rank Exercice'[AREA]));;DESC;Dense
    )

In my case, I wanted to rank by AREA 

 

same thing to order by DISTANCE.

 

And in case, if you want your users to select via a segment which rank to display, just use :

 

RankingCHOICE = 
VAR Unit = SELECTEDVALUE(USER_CHOICE[LIB])
RETURN

SWITCH(TRue();
    Unit = "distance";'DAX_MESURES'[RankingDISTANCE_Summarize_2];
    Unit = "area";'DAX_MESURES'[RankingAREA_Summarize_2])

 

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.