Forum Discussion

Mkaur4360's avatar
Mkaur4360
Regular Visitor
3 years ago
Solved

Find continuous shifts worked using Index

I am working on a shift Data where I need to find continuous shifts. There are instances when an employee has worked two shifts on same day. I want to create an index column where if previous shift s...
  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi Mkaur4360 ,

     

    Please follow the below steps:

    1. Group by the [UserID] and [StartTime]:

    2. Add a index column:

    3. Expand [FinshTime]:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ldJLCsAgDATQu7gWNFO/ZxHvf426qQlJK3QXeZhMxDEcOe9quAIiIMvpXyxpS2xZW2frB6OokUgoHRUmbBSbmLsXfWsLG3fJBjZoK2xFW2Wr2hpb09bZ+h+DCAMzESIOzEyIxrCdD7qO+5esOhlNQrPRIvR5wXkD", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [UserID = _t, StartTime = _t, FinishTime = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"UserID", Int64.Type}, {"StartTime", type date}, {"FinishTime", type date}}),
        #"Grouped Rows" = Table.Group(#"Changed Type", {"UserID", "StartTime"}, {{"Data", each _, type table [UserID=nullable number, StartTime=nullable date, FinishTime=nullable date]}}),
        #"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Index", 1, 1, Int64.Type),
        #"Expanded Data" = Table.ExpandTableColumn(#"Added Index", "Data", {"FinishTime"}, {"FinishTime"})
    in
        #"Expanded Data"

    Best Regards,
    Gao

    Community Support Team

     

    If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

    How to get your questions answered quickly --  How to provide sample data in the Power BI Forum