Calculating average time in transition for only the first time this transition is done

@martins.vanags Dear martins, Thank you for your solution. I need to calculate the time from “In Progress” to “Closed” for the last time.It does work with the following code, but I ran into serious performance problems.As soon as we set the Service Group or Project on the Dimension, we expand, it freezes and pops up an error.So, is there any optimized logic?Thank you very much!

NonZero(
Avg(
Filter(
Descendants([Issue].CurrentHierarchyMember,[Issue].[Issue])
,(
[Measures].[Transitions from status],
[Transition Status].[In progress]
)>0
AND
DateInPeriod( (
[Measures].[Transition from status first date],
[Transition Status].[In progress],
[Time].CurrentHierarchy.DefaultMember
),
[Time].CurrentHierarchyMember
)
)
,
DateDiffDays(
(
[Measures].[Transition to status first date],
[Transition Status].[In progress],
[Time].CurrentHierarchy.DefaultMember
),
(
[Measures].[Transition to status last date],
[Transition Status].[Closed],
[Time].CurrentHierarchy.DefaultMember
)
)

)
)