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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
AGVEGA
Frequent Visitor

Top 3 nearest locations dax

It doesn't work past rank 1, any tips? I am trying to calculate the top three closest representatives.

Closest Clinician 2  =

Var COS1=
'public client_database'[COS Radian Lat1]

Var SIN1=
'public client_database'[Sin Radian Lat1]

VAR Lat1=
'public client_database'[latitude]

Var Lon1=
'public client_database'[longitude]

VAR Clinicianlist=
ADDCOLUMNS(
    SUMMARIZECOLUMNS('public cmr_database - 1 All'[Clinician & Discipline]),
    "@Rank",
    RANKX(VALUES('public cmr_database - 1 All'[Clinician & Discipline]),
    VAR Lat2=CALCULATE(SELECTEDVALUE('public cmr_database - 1 All'[Updated Latitude]))

    VAR Lon2= CALCULATE(SELECTEDVALUE('public cmr_database - 1 All'[Updated Longitude]))

    VAR COS2=CALCULATE(SELECTEDVALUE('public cmr_database - 1 All'[COS Lat2]))

    VAR SIN2=CALCULATE(SELECTEDVALUE('public cmr_database - 1 All'[Sin Lat2]))

    VAR Difference=COS(RADIANS(Lon1-Lon2))

    VAR ACOSCalc=SIN(Lat1*PI()/180)*SIN(Lat2*PI()/180)+COS(Lat1*PI()/180)*COS(Lat2*PI()/180)*COS((Lon2*PI()/180)-(Lon1*PI()/180))

    Return
    IFERROR(ACOS(ACOSCalc)*3959,BLANK()),
    ,
    ASC
    )
)
return
MAXX(FILTER(Clinicianlist,[@Rank]=2),'public cmr_database - 1 All'[Clinician & Discipline])





1 ACCEPTED SOLUTION
some_bih
Super User
Super User

Hi @AGVEGA what is output of your measure? Error maybe?

If yes, check link below as function SUMMARIZECOLUMNS could not be used as part of measure. 

Try to debug / rework you part

ADDCOLUMNS(
    SUMMARIZECOLUMNS('public cmr_database - 1 All'[Clinician & Discipline]),
    "@Rank",
    RANKX(VALUES('public cmr_database - 1 All'[Clinician & Discipline]),
 
Hope this help / kudos appreciated.

https://dax.guide/summarizecolumns/ 





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

Proud to be a Super User!






View solution in original post

1 REPLY 1
some_bih
Super User
Super User

Hi @AGVEGA what is output of your measure? Error maybe?

If yes, check link below as function SUMMARIZECOLUMNS could not be used as part of measure. 

Try to debug / rework you part

ADDCOLUMNS(
    SUMMARIZECOLUMNS('public cmr_database - 1 All'[Clinician & Discipline]),
    "@Rank",
    RANKX(VALUES('public cmr_database - 1 All'[Clinician & Discipline]),
 
Hope this help / kudos appreciated.

https://dax.guide/summarizecolumns/ 





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

Proud to be a Super User!






Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.

Top Solution Authors