Forum Discussion
bocajpedersen
2 years agoNew Member
Calculate time between time-stamp entries based on row conditions
I have a table of swipe entries to a site. On occasions, people can swipe in and out multiple times a day. I want to understand the the time off-site by calculating the difference between the sw...
- 2 years ago
bocajpedersen
Create a blank Query, go to the Advanced Editor, clear the existing code, and paste the codes give below and follow the steps.let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("fZXLbhsxDEV/xfA6RiVK1INrb7xKgXZnBEVReNFF06J1/j+XMylGpJIBZmEf32tx+NL1evx8+/vv9/Phcj4+HM/f77dPX3/+uh0uz+br48v9+PRwPV7O3yrVjt9CPX25/TlRoHQoErowO9ols4Sy44tBAh5vjCQhSwrOGbOVBOHkcRUOkqN38hhrzBKbo11SEppONIpc8TiKODJJoh1jTMtLRo+bhCqheWcxoZLE5CiSxjg17xhjVCdFjxsYErQ58RkSU8mcJTdHuyCxVP2JRkFNFZYiCI6atI+NyA5iCuRxV2fq3tk2CatxDXWgTRJC3fN1bS6kz1KtUhGeQn1P4jBeHNFOheybBHVOb6F2U0hCfcmXw0oyHvY4a7rH7MxOjB5qnT1GDxdJfkAojC3AVcfWUhzX5gEZFWiBIDE6qvXFUE4FSafHH/dtC2Dci8e0dGvac2L0eF08BqOL0RqTM28SdcHr6Fspi88rb5KieYjsKAYukUnrZISEF4nDTUsZm3eW8cj/S3Kk+D/kO03DbCUIlidn1WDjVJK6SVDtorvJUl1Z/M44tzFW9Oa6lgfa1Ue840PzFKHsqG7qoBvwYyMkKa7tajDSiimfstPHFkCtQ58ochPSrm9VWKqbOpgduRipjO/I6J7sqDZrmpcyVdcA3B3VJY/qTqNsJbjWll1ncNWtQv5mpuaOzMXR9f8o+1ibb/Pl0jJYl/JyTz69Ag==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"(blank)" = _t, #"(blank).1" = _t, #"(blank).2" = _t]), #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]), #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Person ID", type text}, {"Date/Time In", type datetime}, {"Date/Time Out", type datetime}}), #"Sorted Rows" = Table.Sort(#"Changed Type",{{"Person ID", Order.Descending}, {"Date/Time In", Order.Ascending}, {"Date/Time Out", Order.Ascending}}), #"Added Index" = Table.AddIndexColumn(#"Sorted Rows", "Index", -1, 1, Int64.Type), #"Added Custom" = Table.AddColumn( #"Added Index", "Custom", each if [Index] >= 0 then let __id = #"Added Index"{[Index]}[Person ID], __pDate = #"Added Index"{[Index]}[#"Date/Time Out"], __cdate = [#"Date/Time In"] in if __id = [Person ID] and Date.From(__pDate) = Date.From(__cdate) then Duration.From(__cdate-__pDate) else null else null, type duration ) in #"Added Custom"
adudani
Memorable Member
2 years agoHi bocajpedersen ,
Here's my approach
1. Add a column subtracting Out - In , as duration.
2. Add a column extracting either date ( assuming both are always the same)
3. Group by person Id and date, aggregation is sum of the duration. ( This should be on site time)
4. Could negate 24 hours from this to get offsite time
If this doesn't resolve the issue , Kindly post the raw data in a table/ readable query format with any other considerations while masking sensitive data.