Forum Discussion

adhumal2's avatar
adhumal2
Icon for Helper III rankHelper III
5 years ago
Solved

Calculating Retirement Date based on Multiple Criterias

Hi Guys,   I am handling a global dataset and I need to calculate retirement date. The retirement date changes from country to country and there are some other factors like employee type, gender, l...
  • MFelix's avatar
    MFelix
    5 years ago

    Hi adhumal2 ,

     

    Don't know how you model is setup, but for the table you present you need to add the following column:

     

    RetirementDate = 
    VAR YOB =
        YEAR ( 'Table'[Date of Birth (MM/DD/YYYY)] )
    VAR MOB =
        MONTH ( 'Table'[Date of Birth (MM/DD/YYYY)] )
    VAR DOB =
        DAY ( 'Table'[Date of Birth (MM/DD/YYYY)] )
    VAR YearsTOR =
        LEFT ( 'Table'[Retirement Criteria ], 2 )
    RETURN
        SWITCH (
            TRUE (),
            'Table'[Country] = "Germany",
                DATE ( YOB + YearsTOR, mob, DOB ) - 1,
            'Table'[Country] = "Switzerland", EOMONTH ( DATE ( YOB + YearsTOR, mob, DOB ), 0 ),
            'Table'[Country] = "France", DATE ( YOB + YearsTOR, 12, 31 ),
            'Table'[Region] = "Latin America",
                DATE ( YOB + YearsTOR, MOB, 1 ) - 1,
            'Table'[Country] = "Japan",
                IF ( MOB <= 6, DATE ( YOB + YearsTOR, 6, 30 ), DATE ( YOB + YearsTOR, 12, 31 ) ),
            'Table'[Country] = "China",
                DATE ( YOB + YearsTOR, mob, DOB ) - 1
        )

     

    This can also be done using a intermidiate table where you have the requiremtns you can do the following:

     

    The criterias I have used are:

    PD - Previous Day
    PM - Previous Month
    EOS - End of Semester
    EOM - End of Month
    EOY - End of Year

     

    Now add the following column to your original table:

    RetirementDate_L =
    VAR YOB =
        YEAR ( 'Table'[Date of Birth (MM/DD/YYYY)] )
    VAR MOB =
        MONTH ( 'Table'[Date of Birth (MM/DD/YYYY)] )
    VAR DOB =
        DAY ( 'Table'[Date of Birth (MM/DD/YYYY)] )
    VAR YearsTOR =
        LOOKUPVALUE (
            'Retirement Criteria'[Retirement Criteria ],
            'Retirement Criteria'[Region], 'Table'[Region],
            'Retirement Criteria'[Country], 'Table'[Country],
            'Retirement Criteria'[Employee Type], 'Table'[Employee Type],
            'Retirement Criteria'[Gender], 'Table'[Gender],
            'Retirement Criteria'[Location], 'Table'[Location]
        )
    VAR TYPETOR =
        LOOKUPVALUE (
            'Retirement Criteria'[Retirement day],
            'Retirement Criteria'[Region], 'Table'[Region],
            'Retirement Criteria'[Country], 'Table'[Country],
            'Retirement Criteria'[Employee Type], 'Table'[Employee Type],
            'Retirement Criteria'[Gender], 'Table'[Gender],
            'Retirement Criteria'[Location], 'Table'[Location]
        )
    RETURN
        SWITCH (
            TYPETOR,
            "PD",
                DATE ( YOB + YearsTOR, mob, DOB ) - 1,
            "PM",
                DATE ( YOB + YearsTOR, MOB, 1 ) - 1,
            "EOS",
                IF ( MOB <= 6, DATE ( YOB + YearsTOR, 6, 30 ), DATE ( YOB + YearsTOR, 12, 31 ) ),
            "EOM", EOMONTH ( DATE ( YOB + YearsTOR, mob, DOB ), 0 ),
            "EOY", DATE ( YOB + YearsTOR, 12, 31 )
        )

     

    Check PBIX file attach,