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

how to calculate period of stay at particular location

Hi all, I am trying to find the time taken by a device to complete a trip from base location to destination & return to base location.
My expected answer is column "Time taken"

// Base location = LOC1
// Time taken should be the time taken by the deviceID to return back to LOC1

Thanks in advance

Captureques.PNG

2 REPLIES 2
kentyler
Solution Sage
Solution Sage

I did these steps in excel

first remove all the rows showing arrival at intermediate destinations

device idlocationtimestampTime DifferenceTime Taken
1112/1/20190.000
1112/6/20195.005
2112/3/2019-3.000
2112/4/20191.001

then calculate the difference between the time for each row and the time for the row above it (since every trip is now reduced to 2 rows)

then take only the differences above 0, these are the time taken

this operation is straightforward in excel, complicated in DAX

once you have shaped the data, the reporting in Power BI will be greatly simplified.

 

if the data is in SQL you could use something like the LAG() function to get access to a different row

Overview of SQL Server LAG() function

SQL Server LAG() is a window function that provides access to a row at a specified physical offset which comes before the current row.





Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


Thanks for your solution.
But I can't delete the rows that are now base location. I need to calculate the time for every location as well.

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.