Forum Discussion

GrahamR99's avatar
GrahamR99
Icon for Resolver I rankResolver I
2 years ago
Solved

Ranking on calculated measure

Hello I have this formula; Distance (Rank) = RANKX(FILTER('Legacy Events Planning 2024','Legacy Events Planning 2024'[Supporter_Postcode]=EARLIER('Legacy Events Planning 2024'[Supporter_Postcode])...
  • Dangar332's avatar
    Dangar332
    2 years ago

    hi, GrahamR99 

    GrahamR99 

     

    try to make new column 

     

    Column = 
    RANK(
         DENSE,
         ALLSELECTED(
             'Table (2)'[Sup Postcode],
             'Table (2)'[Distance (km)]
        ),
        ORDERBY('Table (2)'[Distance (km)],ASC)
        ,,PARTITIONBY('Table (2)'[Sup Postcode])
    )

     

     

     

    if you want to measure then try below code

    Measure 2 = 
    var a = ALL('Table (2)'[Distance (km)],'Table (2)'[Sup Postcode])
    return
    RANK(
        DENSE,
        a,
        ORDERBY(
            'Table (2)'[Distance (km)],
            ASC
        ),,
        PARTITIONBY('Table (2)'[Sup Postcode])
        
    )

     

     

     

  • GrahamR99's avatar
    GrahamR99
    2 years ago

    Hello Dangar332 

    Thank you for the formula, it worked when I change the data.

     

    When I first setup the Power BI report, I used Power BI mesure to calculate the distance between two locations.  When I recreated the data in SQL Server and used it's ablity to calulate the distance, the data was a column and I could use your formula and also slice the distance column in my Power BI report which I could not do when it was a mesure.

     

    The SQL Script I used was;

    DistanceInMiles = GEOGRAPHY::Point([Lat], [Long], 4326).STDistance(GEOGRAPHY::Point([latitude], [longitude], 4326)) / 1609.344

     

    Your formula I used was.

     

    Column = 
    RANK(
         DENSE,
         ALLSELECTED(
             'Table (2)'[Sup Postcode],
             'Table (2)'[Distance (km)]
        ),
        ORDERBY('Table (2)'[Distance (km)],ASC)
        ,,PARTITIONBY('Table (2)'[Sup Postcode])
    )

     

    Thank you for your help.

     

    Regards

     

    GrahamR99