Forum Discussion
Calculating Retirement Date based on Multiple Criterias
- 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 YearNow 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,
parry2k MattAllington @ashishmathur MFelix - Hi experts, can you please guide?
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,