Forum Discussion

Applicable88's avatar
Applicable88
Impactful Individual
5 years ago
Solved

Allocate shift time to Transaction table

Hello,   I know many use the concepts of is-statment to allocate certain times to the right shift time. But is it possible to use a prepared  shift time table to allocate the right shift to the tr...
  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi Applicable88 

     

    I believe there are many ways to do it, you can write nested if then else. Here is one way

     

    sort the reference table, mine is called ShiftTable

     

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bdG7CcMADEXRVYLrQPTkv1cx3n+NpAgYwwFVtxAc6TyHyuc3XZ1XzcdYw/V+xkVxVdwUd8SUYhRbcVScFCWKRJEoEkWilqglaon6FvV9ulKMYity56Q4Ky6Kq+KmuCNGokgUiSJRJIpEkSgSRaJI1BK1RP+/X18=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [StartDate = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"StartDate", type datetime}}),
    
        fnSwitch = (input) => let
            values = List.Zip({ShiftTable[From],ShiftTable[Shift]})
        in
            try List.First(List.Select(values, each _{0 }< input)){1} otherwise "Night",
    
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each fnSwitch(DateTime.Time([StartDate])))
    in
        #"Added Custom"