Forum Discussion

robhel's avatar
robhel
Helper I
7 years ago
Solved

Year Month Calculation on TODAY ()

Hello Guru's

 

Looking for your expert advice on how to achieve the following scenario of calculating the number of Year’s & Months from TODAY() until next lot of Long Service Leave (LSL) will be available.

 

There are 2 parts to this scenario:

 

LSL is available after 10years from commencement date

Additional 9days LSL for every year after 10yrs based on commencement date

 

I’ve came up with an extremely hack work-around for both steps above, which is still not providing me with required results:

 

Step 1)

From my table “CurrentEmployee”, I’ve split [Commencement Date] to DDMM and then included 2019 to it

 

I created a second table for employee’s that are under 10years, adding [Year] + 10 to commencement date

 

Then merged the 2 fields together providing existing LSL & upcoming LSL

 

 

Step 2)

 

I applied a new column with the following:

 

DaysLSL =

 

VAR Months = DATEDIFF(TODAY(),[MergedField],MONTH)

VAR Years = ROUNDDOWN(Months/12,0)

RETURN CONCATENATE(CONCATENATE(Years, “.”),Months-(Years*12)))

 

Which gives me the desired result, unless the date is prior to TODAY (re YMResult)

 

Greatly appreciate any assistance on a way to get desired result

 

EmpIDEmpNameCommDateMergedFieldYMResultYMDesiredResult
123Rod15/10/200715/10/20190.60.6
124Jim2/08/19992/08/20190.40.4
125Barney5/02/20145/02/20244.104.10
126Carl18/02/201918/02/20299.109.10
127Hannah1/03/20081/03/20190.-1.11
128Mary9/12/19999/12/20190.80.8
129Wayne27/06/198327/06/20190.20.2
130Kelly8/01/19858/01/20190.-3.9
131Kirsty1/02/19831/02/20190.-2.10
132Emma4/03/20134/03/20233.113.11
133Lou18/10/199918/10/20190.60.6
134Sarah16/01/200616/01/20190.-3.9
135Mike22/09/200822/09/20190.50.5
136Fred15/04/199915/04/20190.00.0
  • robhel ,

     

    Try to change it as follows.

        CONCATENATE (
            CONCATENATE ( Years, "." ),
            MOD ( Months - ( Years * 12 ) + 12, 12 )
        )

3 Replies

    • robhel's avatar
      robhel
      Helper I

      Thanks for response & in answer to your question, the result is based on TODAY less Commncement MMYY = number of months or years until next allocation of LSL, example

       

      TODAY 27/04/2019 - 12/01/2022 Commencement Date (= 12/01/2012 + 10y) = 2years & 9Mths until LSL

      TODAY 27/04/2019 - 29/10/2019 Commencement DDMM & Current Year (29/10/1979 to 29/10/2019) = .6 mths until next LSL days

       

      Hope this answer your question

      • v-chuncz-msft's avatar
        v-chuncz-msft
        Community Support

        robhel ,

         

        Try to change it as follows.

            CONCATENATE (
                CONCATENATE ( Years, "." ),
                MOD ( Months - ( Years * 12 ) + 12, 12 )
            )