How to filter issue types in different dimension

I’m trying to calculate number of linked bugs to a story and sort them by priority
I succeed to calculate linked bugs and sort by priority but i got also bugs that relates to other bug
(I want only bugs that related to story)

This is what I got so far: