Forum Discussion

MischaT's avatar
MischaT
Frequent Visitor
4 years ago
Solved

DAX - Dynamic Measure based on slicer selection

Hello there! 

 

I need some guidance again please 🙂

 

I am using the following measure to calculate distance: 

 

EVENT TABLE

IDPLACETYPELATLONG
01PRETORIAHAILSTORM-29,3384127,99473
02BLOEMSNOW-25,5273528,04517
03POTCHFLOODING-29,3384131,28885

 

WHAT I WOULD LIKE TO DO:

I would like to create a ID Slicer for the clients. 

 

Based on the selected ID on the slicer, I would like the measure to use the selected ID's LAT and LONG and calculate the distance from the selected ID. 

 

Any suggestions?

 

Would really apprecaite any assistance 

 

Kind Regards, M

 

 

  • AlB's avatar
    AlB
    4 years ago

    MischaT 

    Get the lat, long of the site in the same fashion:

    VAR IDLat = SELECTEDVALUE(EventTable[Lat])

    VAR IDLong = SELECTEDVALUE(EventTable[Long])

    VAR SiteLat = SELECTEDVALUE(SitesTable[Lat])

    VAR SiteLong = SELECTEDVALUE(SitesTable[Long])

    then apply your formulae.

    If this does not work I'd probablyn need a mock pbix reproducing the issue so that I can see exactly what you are doing. You have to share the URL to the file hosted elsewhere: Dropbox, Onedrive... or just upload the file to a site like tinyupload.com (no sign-up required).

     

    Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

    Contact me privately for support with any larger-scale BI needs, tutoring, etc.

     

     

     

4 Replies

  • AlB's avatar
    AlB
    Community Champion

    Hi MischaT 

    The distance between the selected ID and where?

    You can read the selected ID coordinates simply by using:

    VAR IDLat = SELECTEDVALUE(EventTable[Lat])

    VAR IDLong = SELECTEDVALUE(EventTable[Long])

     

    and then use that in hte formula you already have


    Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

    Contact me privately for support with any larger-scale BI needs, tutoring, etc.

     

    • MischaT's avatar
      MischaT
      Frequent Visitor

      Hi @AlB,

       

      Thank you for the response. 

       

      I have tried using the SELECTEDVALUE, but unfortunately it still doesn't work. 

       

      I would like to calculate the distance from the selected ID to each of the ISITES.

      When an ID is then selected, the distance calculation then does not work correctly 

       

      VahidDMDB_ISITES Table:

      SITE NAMETYPEPROVLATLONG
      TropicalBarGP-29,3385027,99473
      SunsetCasinoKZN-29,3384031,28890

       

      I'm very confused as to what is going wrong 

       

      Thank you!

      • AlB's avatar
        AlB
        Community Champion

        MischaT 

        Get the lat, long of the site in the same fashion:

        VAR IDLat = SELECTEDVALUE(EventTable[Lat])

        VAR IDLong = SELECTEDVALUE(EventTable[Long])

        VAR SiteLat = SELECTEDVALUE(SitesTable[Lat])

        VAR SiteLong = SELECTEDVALUE(SitesTable[Long])

        then apply your formulae.

        If this does not work I'd probablyn need a mock pbix reproducing the issue so that I can see exactly what you are doing. You have to share the URL to the file hosted elsewhere: Dropbox, Onedrive... or just upload the file to a site like tinyupload.com (no sign-up required).

         

        Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

        Contact me privately for support with any larger-scale BI needs, tutoring, etc.

         

         

         

  • Hi MischaT 

     

    As AlB  mentioned, it's not clear how do you want to calculate a distance? do you want to replace the selected ID Lat and Long with Lat1 and Long 1 in your formula or Lat 2 and Long 2??? I think you want to replace that with Lat and Long 2!

     

    Can you share a sample of DB_ISITES table?

     

     

    BTW, if you select an ID on a slicer that will filter the EVENT table and then Lat1 and Long1 will return the Lat and Long of the selected ID.

     

    If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
    Appreciate your Kudos!!
    LinkedIn: 
    www.linkedin.com/in/vahid-dm/