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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
MischaT
Frequent Visitor

DAX - Dynamic Measure based on slicer selection

Hello there! 

 

I need some guidance again please 🙂

 

I am using the following measure to calculate distance: 

MischaT_1-1638639618082.png

 

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

 

 

1 ACCEPTED SOLUTION
AlB
Community Champion
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).

 

SU18_powerbi_badge

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.

 

 

 

View solution in original post

4 REPLIES 4
VahidDM
Super User
Super User

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/

 

 

AlB
Community Champion
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


SU18_powerbi_badge

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
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 

MischaT_0-1638785331421.png

 

@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
Community Champion
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).

 

SU18_powerbi_badge

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.

 

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.