Time issue is currently spending In Progress and not Flagged

Hello,

I have a need to get the time an issue is currently spending in the “In Progress” status minus any time it has or is currently spending Flagged. I only need this for issues currently in the “In Progress” status.

For Example:

  • An issue that has been In Progress for 4 hours but was Flagged for 1 hour should yield 3 hours.
  • An issue that has been In Progress for 8 hours but was Flagged twice for 2 hours each should yield 4 hours.
  • An issue that has been In Progress for 6 hours and was Flagged 2 hours ago should yield 4 hours and continue to yield 4 hours until it is unflagged.

I have done similar things in the past using the formula from this article, but the formula depends on the issue transitioning out of a status. In my case, the issue is still in the “In Progress” and the issue may be currently flagged.

How can I achieve this?

Thank you in advance,
Larry