Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
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)
employee | level | training group | L1 start date | L2 start date |
1 | L1 | A | 1/1/2020 | |
1 | L1 | B | 2/1/2020 | |
1 | L1 | C | 3/1/2020 | |
1 | L2 | B | 10/1/2021 | |
1 | L1 | D | 1/1/2021 | |
2 | L1 | A | 3/1/2020 | |
2 | L1 | F | 2/1/2020 | |
2 | L1 | N | 5/1/2020 | |
2 | L2 | A | 3/1/2021 | |
2 | L1 | H | 5/1/2019 | |
2 | L1 | I | 11/1/2018 | |
2 | L2 | H | 7/1/2021 | |
3 | L1 | B | 2/1/2019 | |
4 | L1 | B | 5/1/2020 |
the results needed are below
employee | training group | Time between L1 and L2 |
1 | B | 20 months |
2 | A | 12 months |
2 | H | 26 months |
this is a mock dataset but my real issue is that dates are on two separate rows. any help is appreciated. Thanks
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.
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
@Fair-UL See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395....
The basic pattern is:
Column =
VAR __Current = [Value]
VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])
VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
RETURN
__Current - __Previous
I am not sure I was able to follow this logic. it did not give me the result I was looking for