cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
kstiegler
Advocate I
Advocate I

Removing filters in a distance measure when tables have a common table in between

Hello all,

 

I'm trying to write a measure to calculate distance between two lat/long pairs. The measure works as expected when my tables are NOT related; however, when the relationships are set up as the rest of the report requires, I've been unable to figure out the correct way to implement ALL/REMOVEFILTERS/similar such that the measure still works when the relationships are active.

 

Here's the working measure:

 

 

 

Distance to Owner = 
var Lat1 = MIN(SystemUser[Employee Latitude])
var Lng1 = MIN(SystemUser[Employee Longitude])

var Lat2 = MIN(Account[Latitude])
var Lng2 = MIN(Account[Longitude])
---- Algorithm here -----
var P = DIVIDE( PI(), 180 )
var A = 0.5 - COS((Lat2-Lat1) * p)/2 + 
    COS(Lat1 * p) * COS(lat2 * P) * (1-COS((Lng2- Lng1) * p))/2
var final = 12742 * ASIN((SQRT(A))) * 0.621371
return final

 

 

 

 

Here's the SystemUser table:

Employee IDEmployee LatitudeEmployee Longitude
145-90
246-91

 

Here's the Account table:

Account IDAccount LatitudeAccount Longitude
A45-90
B46-91

 

There is an intermediate table in between the above tables:

IntermediateIDOwner IDAccount ID
XYZ1A
ABC2B

 

Relationships:

SystemUser[Employee ID] one-to-many IntermediateTable[Owner ID] , cross filter direction is single from SystemUser -- > IntermediateTable

Account[AccountID] one-to-many IntermediateTable[Account ID], cross filter direction is BOTH

 

The goal is to be able to calculate distance between Employees and Accounts, and I've been testing my revised measure in a matrix like this :

 Account AAccount B
Employee 1 |5 miles10 miles
Employee 2 |7 miles12 miles

 

As the measure is currently written, however, I only get the same vastly incorrect numbers (~6,300 miles) for all entries in the matrix. I expect that the solution to my issue correcting the measure to remove the filters, but I've been unable to figure it out thus far and I'm hoping someone with more experience with ALL/REMOVEFILTERS/etc. may have some insight.

1 REPLY 1
amitchandak
Super User
Super User

@kstiegler , can you create a column?

If they are related, You can bring in a column using related or relatedtable in another table

 

refer 4 ways to copy data from one table to another
https://www.youtube.com/watch?v=Wu1mWxR23jU
https://www.youtube.com/watch?v=czNHt7UXIe8

 

 



Features || Datamarts: https://youtu.be/8tskWsJTEpg || Field Parameters : https://youtu.be/lqF3Wa1FllE?t=70
Learn Power BI P&L Statement || Time Intelligence Decoded : https://youtu.be/aU2aKbnHuWs&t=145s ||
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!
Dashboard of My Blogs !! Connect on Linkedin !! Subscribe to my youtube Channel !!!! How to get Quick Help !!
Resources | Master Power BI !! Expertise Power BI !! Power BI For Tableau User !!

Helpful resources

Announcements
Difinity Conference

Difinity Conference 2022

Difinity is the largest Microsoft Data, AI, Power BI, Power Platform and Business Applications Conference in New Zealand.

European Share Point Conference

European Share Point Conference

This conference returns live and in-person in Copenhagen this 28 November-01 December with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Microsoft 365 Conference â__ December 6-8, 2022

Microsoft 365 Conference - 06-08 December

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Top Solution Authors