Forum Discussion
spread calls duration that exceed 30 mins over multiple 30 mins intervals over the day.
- 6 years ago
Hello Anonymous
I've created something really nice
But I think the logic has to be changed, meaning, creating a talble, considering the lowest start time and the highest end time and then connect to the call-table to do the calculation
let Quelle = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjTWMzTSMzIwtFQwsLAyMFDSQRMyNgUKJSfm5CjF6qArNzFFU26JrDwWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Start = _t, End = _t, Type = _t]), ChangeType = Table.TransformColumnTypes ( Quelle, { {"Start", type datetime}, {"End", type datetime}, {"Type", type text} } ), GetListTimesStart = List.DateTimes ( List.Min ( ChangeType[Start] ) - #duration(0,0,Time.Minute ( List.Min ( ChangeType[Start] ) ),0), Duration.Minutes ( List.Max ( ChangeType[End] ) - List.Min ( ChangeType[Start] ) ) / 30+2, #duration(0,0,30,0) ), GetListTimeEnd = List.Transform(GetListTimesStart, each _ + #duration(0,0,30,0)), CreateTabel = Table.FromColumns({GetListTimesStart,GetListTimeEnd}, {"Start", "End"}), AddCallTable = Table.AddColumn ( CreateTabel, "Merge Tables", (Time)=> Table.SelectRows ( ChangeType, (select)=> select[Start]<=Time[End] and Time[Start] <= select[End] ) ), ExpandCallTimes = Table.ExpandTableColumn ( AddCallTable, "Merge Tables", {"Start", "End", "Type"}, {"Call.Start", "Call.End", "Type"} ), ChangeToDateTime = Table.TransformColumnTypes ( ExpandCallTimes, { {"Start", type datetime}, {"End", type datetime}, {"Call.Start", type datetime}, {"Call.End", type datetime}} ), CalculateDuration = Table.AddColumn ( ChangeToDateTime, "Duration", each Duration.TotalSeconds ( (if [End]<[Call.End] then [End] else [Call.End])- (if [Call.Start]>[Start] then [Call.Start] else [Start]) ) ), DeleteCallColumns = Table.RemoveColumns ( CalculateDuration, {"Call.Start", "Call.End"} ) in DeleteCallColumnsWhat do you think about it?
If this post helps or solves your problem, please mark it as solution.
Kudos are nice to - thanks
Have fun
Jimmy
Hello Anonymous
I've created something really nice
But I think the logic has to be changed, meaning, creating a talble, considering the lowest start time and the highest end time and then connect to the call-table to do the calculation
let
Quelle = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjTWMzTSMzIwtFQwsLAyMFDSQRMyNgUKJSfm5CjF6qArNzFFU26JrDwWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Start = _t, End = _t, Type = _t]),
ChangeType = Table.TransformColumnTypes
(
Quelle,
{
{"Start", type datetime},
{"End", type datetime},
{"Type", type text}
}
),
GetListTimesStart = List.DateTimes
(
List.Min
(
ChangeType[Start]
)
-
#duration(0,0,Time.Minute
(
List.Min
(
ChangeType[Start]
)
),0),
Duration.Minutes
(
List.Max
(
ChangeType[End]
)
-
List.Min
(
ChangeType[Start]
)
)
/ 30+2,
#duration(0,0,30,0)
),
GetListTimeEnd = List.Transform(GetListTimesStart, each _ + #duration(0,0,30,0)),
CreateTabel = Table.FromColumns({GetListTimesStart,GetListTimeEnd}, {"Start", "End"}),
AddCallTable = Table.AddColumn
(
CreateTabel,
"Merge Tables",
(Time)=> Table.SelectRows
(
ChangeType,
(select)=> select[Start]<=Time[End] and Time[Start] <= select[End]
)
),
ExpandCallTimes = Table.ExpandTableColumn
(
AddCallTable,
"Merge Tables",
{"Start", "End", "Type"},
{"Call.Start", "Call.End", "Type"}
),
ChangeToDateTime = Table.TransformColumnTypes
(
ExpandCallTimes,
{
{"Start", type datetime},
{"End", type datetime},
{"Call.Start", type datetime},
{"Call.End", type datetime}}
),
CalculateDuration = Table.AddColumn
(
ChangeToDateTime,
"Duration",
each Duration.TotalSeconds
(
(if [End]<[Call.End] then [End] else [Call.End])-
(if [Call.Start]>[Start] then [Call.Start] else [Start])
)
),
DeleteCallColumns = Table.RemoveColumns
(
CalculateDuration,
{"Call.Start", "Call.End"}
)
in
DeleteCallColumns
What do you think about it?
If this post helps or solves your problem, please mark it as solution.
Kudos are nice to - thanks
Have fun
Jimmy
Hi Jimmy,
I woulk like to thank you for your solution, it's magic :), as I am a newbie with Power Query (1 month experience) so it took me like two days to be able to adjust your solution to my need (table and datetime start and so on. 🙂 ). much appreciated thanks again.
- Jimmy8016 years ago
Community Champion
Hello Anonymous
great that the time spent for your solution was good for something
have a nice day
Jimmy
- Anonymous6 years agoNot applicable
Hi Jimmy,
I have just realized that my liste of intervals changes according to the StartTime=StatusDateTime in my Called table.
so I have to change this part of code every day to adjust it to get the interval like: 12:00:00 to 12:30:00 and so on... instead of( 12:35:03 to 01:05:03).
from my side I did some change to this part of code for today to get the right intervals:
= List.DateTimes
(StartDate - #duration(0,0,Time.Minute( List.Min(ChangeType[StatusDateTime])- #duration(0,0,-35,0)),0),
Duration.Minutes(List.Max(ChangeType[StatusDateTime]) - List.Min(ChangeType[StatusDateTime])) / 3+30, #duration(0,0,30,0) )Is there any way to have my liste of Intervals fixed as shown below and independent of the start time of my called table.
thanks in advance.
- Jimmy8016 years ago
Community Champion
Hello
If i remember right the list is created dynamically depending on the datetimes found in the database and starting always at full hour.
So i don't understand the issue. You could apply a time filter on top to visualise only today's data, or I'm missing something?
Jimmy