Forum Discussion
Anonymous
5 years agoNot applicable
Unique timeline from the overlapping time stamp
Hello Everyone, I am trying to summarize the timeline of resources who are logging in 'downtime' for the applications. The details from the PowerApps is captured in the below format: Employe...
Anonymous
5 years agoNot applicable
Hi Anonymous
Only use the Start Time and End Time, so the number is slightly different from the difference,
M solution:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("zZPNqsIwEIVfRboWnEwyUbMT3blTXImLIkEL17a01ee3PyJmUivFe/VCFp1Twvkmc2a7DVY2T87Z3g5EMAxmafoT7cMiSuK6BhyBGiGgGAgykjxJQSWBATKgy8/1ObXZJcqTrL6/sGmYFScbF3U5P9o4DqPK6NBou+G/JsCvE8iPE+DLKagWCW8EYJBcAnQJsD+BPwXVIsk7gZy8SyAZgfLsiBNoQ/VghAFZHpdAugSyP4Hf8F8TKEbAYzc2NPGl6X0KguVAuQRVuVk+M6cX7fvmKJrklb3j2FuDXuaameuenUN3/pg5dj8737XuznXz97eeneUe0dt9LE1vu69Es4QP5uSaU3vqdlc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Employee = _t, #"App Category" = _t, #"Start Time" = _t, #"End Time" = _t, Difference = _t, Supervisor = _t, Department = _t, Location = _t, #"Resolved by" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Employee", type text}, {"App Category", type text}, {"Start Time", type datetime}, {"End Time", type datetime}, {"Difference", type time}, {"Supervisor", type text}, {"Department", type text}, {"Location", type text}, {"Resolved by", type text}}),
#"Inserted Date" = Table.AddColumn(#"Changed Type", "Date", each DateTime.Date([Start Time]), type date),
#"Sorted Rows" = Table.Sort(#"Inserted Date",{{"Start Time", Order.Ascending}}),
#"Grouped Rows" = Table.Group(#"Sorted Rows", {"Employee", "Date"}, {{"allrows", each _, type table [Employee=nullable text, App Category=nullable text, Start Time=nullable datetime, End Time=nullable datetime, Difference=nullable time, Supervisor=nullable text, Department=nullable text, Location=nullable text, Resolved by=nullable text, Date=date]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each [a=Table.AddIndexColumn([allrows],"Index",0,1),
b=Table.ExpandRecordColumn(
Table.AddColumn(
a,
"MaxTime",
(OT) =>
Table.Max(
Table.SelectColumns(
Table.SelectRows(a, (IT) => IT[Index] <= OT[Index]),
"End Time"
),
"End Time"
)
),
"MaxTime",
{"End Time"},
{"MaxTime"}
),
c=Table.AddColumn(
b,
"Break",
each [
x = try b[Start Time]{[Index] + 1} - [MaxTime] otherwise 0,
y = Duration.From( if Number.From(x) > 0 then x else 0)
][y]
)][c]),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Downtime", each List.Max([Custom][End Time])- List.Min([Custom][Start Time])-Duration.From( List.Sum([Custom][Break]))),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"allrows", "Custom"})
in
#"Removed Columns"
DAX solution:
calculated column
Break =
VAR CurEmployee = overlap[Employee]
VAR CurDate = overlap[Date]
VAR CurrentTime = overlap[Start Time]
VAR PreviousMax =
CALCULATE (
MAX ( overlap[End Time] ),
FILTER (overlap, overlap[Start Time] < CurrentTime && overlap[Date]=CurDate&&overlap[Employee]=CurEmployee)
)
VAR MaxTime =
COALESCE( PreviousMax, [End Time])
VAR Break =
IFERROR(DATEDIFF(MaxTime,CurrentTime,SECOND),0)
RETURN
IF(Break<0,0,Break)
measure
Downtime =
VAR Totalsecs = DATEDIFF(MIN(overlap[Start Time]),MAX(overlap[End Time]),SECOND) - SUM(overlap[Break])
VAR Hours = INT(Totalsecs/3600)
VAR Mins = INT((Totalsecs-Hours*3600)/60)
VAR Secs = Totalsecs-Hours*3600-Mins*60
RETURN
Hours&":"&Mins&":"&Secs
- Anonymous5 years agoNot applicable
Thanks for this solution Vera, I am testing this solution and would share update with you shortly.