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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
clevasight
New Member

Velocity of Each User every time longitude & latitude is captured (Excel Example/Solution Provided)

I have GPS locations for many users arranged by datetime. I would like to pull this from from the DB in Power BI and create a new column for distance and another for velocity for each user between two longitude and latitude coordinates. 

BCDEFGH
agent_user_idlongitudelatitudelocation_actionverification_idverification_typecreated_at
37993.420616.42999IN_TRANSIT457265ADDRESS08/11/2021 18:01
475936.98254.81352IN_TRANSIT457435ADDRESS08/11/2021 18:01
37993.420676.43015IN_TRANSIT457265ADDRESS08/11/2021 18:03
408235.736395.54055ONLINE0NONE08/11/2021 18:03
426775.588486.2923ONLINE0NONE08/11/2021 18:03
475936.98254.81352IN_TRANSIT457435ADDRESS08/11/2021 18:03
260357.065344.84438ONLINE0NONE08/11/2021 18:04
260357.065344.84438ONLINE0NONE08/11/2021 18:04

 

In excel I did this by sorting the columns first by agent_user_id then by created_at. I then used the below formulas to calculate time between pings, distance between coordinates and velocity. For time and distance, the if statement does the calculation only if its the same agent_user_id else results in 0. Columns listed above begin with B.

time_hrdistance_kmkmph
=IF(B2=B1,(H2-H1)*24,0)=IF(B2=B1,ACOS(COS(RADIANS(90-D2)) * COS(RADIANS(90-D1)) + SIN(RADIANS(90-D2)) * SIN(RADIANS(90-D1)) * COS(RADIANS(C2-C1))) * 6371,0)=IFERROR(J2/I2,0)
1 REPLY 1
Greg_Deckler
Super User
Super User

@clevasight So, you can get the Distance using this quick measure: Going the Distance - Microsoft Power BI Community

 

You can get the previous value using the pattern from MTBF: See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395....
The basic pattern is:
Column = 
  VAR __Current = [Value]
  VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])

  VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
RETURN
  __Current - __Previous

 

You can just subtract the two date/times and then multiply by 24*60*60 to get the number of seconds or just 24 for hours or 24*60 for minutes.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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