Calculate Impact Score using Linked Bugs

Hello everyone,

I’m currently trying to create a new report which calculates the Bug Impact Score of each sprint. This metric uses a factor revel with the level of impact (Low -1 , Medium - 3, High - 7) and multiplies this by the number of bugs in each impact level.

The nuance is that I need to calculate this metric with relation to the sprint where the User Story the Bugs are linked to where closed.

I am able to count the number of bugs for each user story in a sprint using this metric:

CASE WHEN
    [Sprint].Currentmember.Level.name = "Sprint"
THEN
  NonZero(Sum(
    Filter(
      Descendants([Issue].Currentmember, [Issue].[Issue]),
      NOT isEmpty([Issue].CurrentHierarchymember.Get('Bugs'))
      AND
      DateCompare(
        [Issue].CurrentHierarchyMember.Get('Created at'),
        [Sprint].CurrentMember.Get('End date')) <= 0
      AND
     [Measures].[Sprint issues at closing] > 0)
  ,
   -- retrieve Bugs information from Issue property Bugs
  Nonzero(Count(
    [Issue].CurrentHierarchy.GetLinkedmembers('Bugs')
  ))
  
  )
  )
END

However I need the next step which is to calculate the impact store, and for that I need to get to the impact each bug has.

How can I do this?

Thanks!