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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.