You should solve with this expression:
sum(/Root/Items/Item[RecordNo -1=/Root/Entries/Entry[IsValid=1]/RecordNo]/Cost)
The problem with yours is that you are messing up with the context node, remember that any relative path expression in the predicate (the expression you put between the brackets) refers to the current element, the one that will be picked in case the expression evaluates to true.