You probably already know this, but the format for setting a variable using the /set command is /set %variable <value>
This sets a global variable.
Using the /var command the format is /var %variable = <value>
This sets a local variable.

While I have seen variables set using the format that you have used in your command line sequence, the only time I've seen it done is in a script format, not in a direct command line.

I tested this out, and while your command line code does work as you say, if you put in the var before the %i after the first pipe, then it does give the proper output.

I suspect that using %variable = <value> without the var command will only work in a scripted situation, but not in a direct command line.