Thanks, it's clear now.
It must be a bad habit of going every time via variables with explicitly defined types (either scalar or table ) which prevented me from hitting this wall before.
Indeed, if we skip @x and try to pull it directly from the subquery, it will fail.
_____________
Code for TallyGenerator