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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Why RANKX function does not group correctly?

Hello

I am trying to rank WharHouse_City by Ship_to_City. I am trying to find out which ship is close to my warehouse city. I have tested a few formulas. It did not work. One of the community members ( thanks to Sumanth_23 ) showed me the Rank distance New and other one was tested by me.

I am gettign something like this,

Capture11.PNG

 but I want something like this,

Capture1.PNG

 I know I have a blank ship to city, but  I dont think it's going to affect me right. Can anybody please tell me what I am doing wrong? I have been trying this for one week and could not figure it out.

I also have attched my sample file. 

https://drive.google.com/file/d/1neCrwh9hWwAZhVqHO9z0UqYQG73tUsD5/view?usp=sharing%C2%A0%C2%A0 

I have tried following formulas, but did not work. 

Rank_Distance NEW = 
    VAR _Rnk =
        RANKX(
        FILTER(
            'Sample_Rank_Data', 
            'Sample_Rank_Data'[Ship_to_City]= EARLIER('Sample_Rank_Data'[Ship_to_City]) 
            && 'Sample_Rank_Data'[Distance] <> BLANK()
            ),
        'Sample_Rank_Data'[Distance],
        ,
        ASC, 
        DENSE)
    RETURN
        IF('Sample_Rank_Data'[Distance] = BLANK(), BLANK(), _Rnk)
Rank Test = 
IF (
    ISINSCOPE( Sample_Rank_Data[Ship_to_City] ),
    RANKX (
        CALCULATETABLE (
            VALUES ( Sample_Rank_Data[Ship_to_City] ),
            ALLSELECTED ( Sample_Rank_Data[Ship_to_City] )
        ),
        Sample_Rank_Data[Distance]
    )
)

Thank you so much

1 REPLY 1
Anonymous
Not applicable

I figure it out. It has to be unique number. In my case, Document No. I was using Ship to city which has same cities for each order. 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors