Problem counting instances

Hi
I have a form that is parent and child of itself, and need to count how many previous entry there are with the same value on a question called pcode.

This formula counts how many entries there are previously and work fine
count(instance(‘ria_formb’)/root/data[pcode])

But this should count how many entries there are previously with same value in pcode and but it does not count and I cant understand why
count(instance(‘ria_formb’)/root/data[pcode=current()/…/pcode])

Any help?
Gracias
Pablo

@pschweitzer, have you gone through our support article that has all the workarounds you should need related to the dynamic data attachment?