Simplify how substituting values works

The original purpose of this PR was to add a test for AnyValues filters, but it got a bit out of hand fixing the existing code.