Forum Discussion
ToreVingare
5 years agoFrequent Visitor
Stop row based on next row, process mining
Hello! I'm working on a process mining dashboard. In this dashboard I'm mapping a patient journey in our hospital. The process looks like this. Patient arrives at a ward -> Is rushed to surgery -...
ziying35
5 years agoImpactful Individual
I have partially modified the raw data you provided, using the source data, which I think is fine, The following is the code I wrote, the code uses the List.Accumulate function, currently can handle the amount of data 8000 lines, if you form the amount of data more, you can modify my code into a custom function, and then you split the source data by 8000 lines of the base, and finally iterate through the List.Transform function on it!
// output
let
Source = Table.FromRecords(Json.Document(Binary.Decompress(Binary.FromText("jdK9asMwFAXgVymaLbg/cmPfzZAMgQ4Fmyyhg2lKyWIHxwmE0nevVJektaSooO3ofkhH2n6o9VIJZqoe22FUogiw1EAaTIMg4JbK1Krb/c7yBgsBM2VP/Ws77vvObqjOuwdUn1lCZQyqNiMh9NT6NLy/DZe0TJJH5UJM7snP/XHU/SHl3mZ9twy56011NWluskZ0Jpe+aTN2DdEi0W1UDZ30O6Pba97tNizbaeagTA0aMWWy25A73bUIuQyN/Qr8GOyBrirPVATN6FRDnoqoAd2Lgf/H/rYbV/2z/mT0v3Yjsp1exORc6E67L18=", BinaryEncoding.Base64),Compression.Deflate))),
rows = Table.ToRows(Source)&{{""}},
acc = List.Accumulate(
rows,
{{},"","",{},{}},
(s,c)=>
if s{1}<>c{0} then { if Text.StartsWith(s{4}?{3}? ??c{3}, "Avd") then s{0}
else s{0}&{{s{4}?{0}?, s{4}?{2}?, s{3}?{2}?, s{3}?{3}? }}, c{0}, c{3}, c, c
}
else if Text.StartsWith(s{4}?{3}? ??c{3}, "Avd") then { s{0}&{{s{4}{0}, s{4}{1}, c{1}, s{4}{3}}}&{c}, c{0}, c{3}, s{3}, c }
else if c{1}>s{3}{2} then { s{0}&{{s{4}{0}, s{4}{2}, s{3}{2}, s{3}{3}}}&{c}, c{0}, c{3}, s{3}, c }
else { s{0}&{c}, c{0}, c{3}, s{3}, c }
),
toTbl = Table.FromRows(acc{0}, Table.ColumnNames(Source)),
chType = Table.TransformColumnTypes(toTbl,{{"Start", type datetime}, {"End", type datetime}})
in
chType