Forum Discussion

Fair-UL's avatar
Fair-UL
Helper II
4 years ago

Calculate Time between two dates on different rows

My issue is a bit tricky. I have this mock dataset with employees, levels, training group, and dates of start of level. not all employees are L2 in all training groups. I want to be able to calculate the time between L1 and L2 for every training group. if there is no L2 date, then I don't care about that entry. the results I want are in the second table (time in months)

employeeleveltraining groupL1 start dateL2 start date
1L1A1/1/2020 
1L1B2/1/2020 
1L1C3/1/2020 
1L2B 10/1/2021
1L1D1/1/2021 
2L1A3/1/2020 
2L1F2/1/2020 
2L1N5/1/2020 
2L2A 3/1/2021
2L1H5/1/2019 
2L1I11/1/2018 
2L2H 7/1/2021
3L1B2/1/2019 
4L1B5/1/2020 

 

the results needed are below

employeetraining groupTime between L1 and L2
1B20 months
2A12 months
2H26 months

 

this is a mock dataset but my real issue is that dates are on two separate rows. any help is appreciated. Thanks

4 Replies

    • Fair-UL's avatar
      Fair-UL
      Helper II

      Greg_Deckler 

      I am not sure I was able to follow this logic. it did not give me the result I was looking for

  • v-henryk-mstf's avatar
    v-henryk-mstf
    Community Support

    Hi Fair-UL ,

     

    According to your description, I did a test reference as follows:

     

    col_l2 =
    CALCULATE (
        MIN ( 'Table'[L1 start date] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[training group] = EARLIER ( 'Table'[training group] )
        )
    )
    Col = 
    var a = MONTH('Table'[L2 start date])-MONTH('Table'[col_l2])
    var b = YEAR('Table'[L2 start date])-YEAR('Table'[col_l2])
    return
    IF('Table'[L2 start date]<>0,IF(a>=0, b*12+a,b*12-a))

    If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.


    Best Regards,
    Henry


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

    • Fair-UL's avatar
      Fair-UL
      Helper II

      Hi v-henryk-mstf 

      the issue is in column col_l2, I need to calculate the time between L1 and L2 start dates for any employee who has L2 in a training group. So, for employee1, I need to find the time between  2/1/2020 and 10/1/2021 [20 months] . any other L1 start date can be ignored for any training groups for that employee unless he has another L2 start date for another training group