Forum Discussion

BZLykke_KAB's avatar
BZLykke_KAB
New Member
3 years ago
Solved

Sort date/time column into time slots in new column

I would like to sort each row in creationDate (see below) into 4 time slots (24h format) into a new column   07:00:00 - 09:59:59 10:00:00 - 12:59:59 13:00:00 - 15:59:59 16:00:00 - 06:59:59   M...
  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi BZLykke_KAB 

    You can refer to the following column

    Range =
    VAR a = {
        "07:00:00-09:59:59",
        "10:00:00-12:59:59",
        "13:00:00-15:59:59",
        "16:00:00-06:59:59"
    }
    VAR b =
        ADDCOLUMNS (
            a,
            "lefttime", TIMEVALUE ( LEFT ( [Value], SEARCH ( "-", [Value] ) - 1 ) ),
            "rightvalur",
                TIMEVALUE (
                    MID (
                        [Value],
                        SEARCH ( "-", [Value] ) + 1,
                        LEN ( [Value] ) - SEARCH ( "-", [Value] )
                    )
                )
        )
    VAR c =
        ADDCOLUMNS (
            b,
            "Detaillefttime",
                IF (
                    [lefttime] > TIME ( 12, 00, 00 )
                        && [rightvalur] < TIME ( 12, 00, 00 ),
                    [rightvalur] + 1,
                    [rightvalur]
                )
        )
    VAR d =
        TIMEVALUE ( [Date] )
    RETURN
        MINX ( FILTER ( c, [lefttime] < d && [Detaillefttime] >= d ), [Value] )
    

     

    Best Regards!

    Yolo Zhu

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.