Forum Discussion

heygowtam's avatar
heygowtam
Helper II
3 years ago
Solved

Switch Statement is not Working

I have two Columns [Employment Type] and [start Date] 1) if the employee is a full-time and started before Finacial Year he gets full Leave ie 20 2) If the Employee Joins the Current Finacial Year...
  • Anonymous's avatar
    Anonymous
    3 years ago

    HI heygowtam.

    I'd like to suggest you try to use the following calculated column formula with logic operators instead of DATESBETWEEN function:

    Leaves =
    SWITCH (
        TRUE (),
        [Start date] <= DATE ( 2022, 07, 01 ),
            IF (
                [Employment Type] = "Full Time",
                20,
                IF ( [Employment Type] = "Part Time", 12 )
            ),
        [Start date] > DATE ( 2022, 07, 01 )
            && [Start date] <= DATE ( 2022, 08, 01 ),
            IF (
                [Employment Type] = "Full Time",
                20,
                IF ( [Employment Type] = "Part Time", 12 )
            ),
        [Start date] > DATE ( 2022, 08, 01 )
            && [Start date] <= DATE ( 2022, 09, 01 ),
            IF (
                [Employment Type] = "Full Time",
                18.37,
                IF ( [Employment Type] = "Part Time", 11 )
            ),
        [Start date] > DATE ( 2022, 09, 01 )
            && [Start date] <= DATE ( 2022, 10, 01 ),
            IF (
                [Employment Type] = "Full Time",
                16.70,
                IF ( [Employment Type] = "Part Time", 10 )
            ),
        [Start date] > DATE ( 2022, 10, 01 )
            && [Start date] <= DATE ( 2022, 11, 01 ),
            IF (
                [Employment Type] = "Full Time",
                15,
                IF ( [Employment Type] = "Part Time", 9 )
            ),
        [Start date] > DATE ( 2022, 11, 01 )
            && [Start date] <= DATE ( 2022, 12, 01 ),
            IF (
                [Employment Type] = "Full Time",
                13.36,
                IF ( [Employment Type] = "Part Time", 8 )
            ),
        [Start date] > DATE ( 2022, 12, 01 )
            && [Start date] <= DATE ( 2023, 01, 01 ),
            IF (
                [Employment Type] = "Full Time",
                11.7,
                IF ( [Employment Type] = "Part Time", 7 )
            ),
        [Start date] > DATE ( 2023, 01, 01 )
            && [Start date] <= DATE ( 2023, 02, 01 ),
            IF (
                [Employment Type] = "Full Time",
                10,
                IF ( [Employment Type] = "Part Time", 6 )
            ),
        [Start date] > DATE ( 2023, 02, 01 )
            && [Start date] <= DATE ( 2023, 03, 01 ),
            IF (
                [Employment Type] = "Full Time",
                8.35,
                IF ( [Employment Type] = "Part Time", 5 )
            ),
        [Start date] > DATE ( 2023, 03, 01 )
            && [Start date] <= DATE ( 2023, 04, 01 ),
            IF (
                [Employment Type] = "Full Time",
                6.68,
                IF ( [Employment Type] = "Part Time", 4 )
            ),
        [Start date] > DATE ( 2023, 04, 01 )
            && [Start date] <= DATE ( 2023, 05, 01 ),
            IF (
                [Employment Type] = "Full Time",
                5,
                IF ( [Employment Type] = "Part Time", 3 )
            ),
        [Start date] > DATE ( 2023, 05, 01 )
            && [Start date] <= DATE ( 2023, 06, 01 ),
            IF (
                [Employment Type] = "Full Time",
                3.34,
                IF ( [Employment Type] = "Part Time", 2 )
            ),
        [Start date] > DATE ( 2023, 06, 01 )
            && [Start date] <= DATE ( 2023, 07, 01 ),
            IF (
                [Employment Type] = "Full Time",
                14.67,
                IF ( [Employment Type] = "Part Time", 1 )
            )
    )

    Regards,

    Xiaoxin Sheng