Forum Discussion

CoreyB76's avatar
CoreyB76
New Member
6 years ago
Solved

Employee Shift Grouping

Here's the problem I am trying to solve with Power Query. As a caveat, I am very new at using this tool but I think that it should be able to help me solve this problem.   We have many employees th...
  • Jimmy801's avatar
    6 years ago

    Hello CoreyB76 

     

    you can add new column to check if an ID was split or was split. WIth this parameter you can filter your table (not splitted canceled) and make the check >16 only on rows that were not splitted. Here a practicable example

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjG0MDWzVNJRAiJDAz0DQz0jAyMDICe4tDgxT8E5sSg1PbMstQgo4pSfpOCcn1dcmgvm+nqBtJgDCefEvOTUnNQUpVgdiIGWZkBRuMnkGAtS6lhQUJRfhmysObqxRqQZa47VVEtThPeNYQa6pCYlVaIY6JWfkYdiYgBIjwV2I5FC1JxUI0F6A1LzUjLz0pViYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Punch ID" = _t, #"Reference Punch ID" = _t, #"Date Of Service" = _t, Employee = _t, Client = _t, #"Cost Center" = _t, Hours = _t, Status = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Punch ID", Int64.Type}, {"Reference Punch ID", Int64.Type}, {"Date Of Service", Int64.Type}, {"Employee", type text}, {"Client", type text}, {"Cost Center", type text}, {"Hours", Int64.Type}, {"Status", type text}}),
        AddIsSplit = Table.AddColumn
        (
            #"Changed Type",
            "IsSplit",
            each List.Contains(#"Changed Type"[Reference Punch ID], [Punch ID]),
            type logical
        ),
        FilterCancelNotSplitted = Table.SelectRows
        (
            AddIsSplit,
            each not ([Status]="Canceled" and [IsSplit]=false)
        ),
        AddWasSplit = Table.AddColumn
        (
            FilterCancelNotSplitted,
            "WasSplit",
            each List.Contains(AddIsSplit[Punch ID], [Reference Punch ID]),
            type logical
        ),
        Over16 = Table.AddColumn
        (
            AddWasSplit,
            "Over16",
            each if [WasSplit]= false and [Hours]>16 then true else false,
            type logical
        )
    in
        Over16

     

    Copy paste this code to the advanced editor in a new blank query to see how the solution works.

    If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
    Kudoes are nice too

    Have fun

    Jimmy