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.
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.
B | C | D | E | F | G | H |
agent_user_id | longitude | latitude | location_action | verification_id | verification_type | created_at |
3799 | 3.42061 | 6.42999 | IN_TRANSIT | 457265 | ADDRESS | 08/11/2021 18:01 |
47593 | 6.9825 | 4.81352 | IN_TRANSIT | 457435 | ADDRESS | 08/11/2021 18:01 |
3799 | 3.42067 | 6.43015 | IN_TRANSIT | 457265 | ADDRESS | 08/11/2021 18:03 |
40823 | 5.73639 | 5.54055 | ONLINE | 0 | NONE | 08/11/2021 18:03 |
42677 | 5.58848 | 6.2923 | ONLINE | 0 | NONE | 08/11/2021 18:03 |
47593 | 6.9825 | 4.81352 | IN_TRANSIT | 457435 | ADDRESS | 08/11/2021 18:03 |
26035 | 7.06534 | 4.84438 | ONLINE | 0 | NONE | 08/11/2021 18:04 |
26035 | 7.06534 | 4.84438 | ONLINE | 0 | NONE | 08/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_hr | distance_km | kmph |
=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) |
@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.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
41 | |
21 | |
21 | |
14 | |
13 |
User | Count |
---|---|
43 | |
36 | |
33 | |
18 | |
18 |