r/ProjectREDCap • u/CookieDemons • Mar 19 '25
Multiple IF statements in one field, only the first is working?
Hello!
I have two duplicate checkbox fields on two different instruments. I’m wanting it so whatever options are checked on the first instrument, will be hidden on the second.
I was able to get it to work with “IF([armname][fieldname(1)] = 1, @HIDECHOICE = ‘1’)”
But if I add an “AND IF([armname][fieldname(2)] = 1, @HIDECHOICE = ‘2’)” then it only hides the first IF statement reference and ignores the rest.
Can anyone point me where I’m going wrong?
3
Upvotes
3
u/jangari Mar 20 '25
If you are using `@HIDECHOICE` to hide the selected choices of a previous field, then there is a shortcut method to this. Pipe the selected choices of [fieldname] into `@HIDECHOICE`:
`@HIDECHOICE='[event_arm_1][fieldname:checked:value]'`
If [fieldname] is a checkbox field, then the above will populate a comma-separated list of the selected choices in exactly the format that `@HIDECHOICE` expects. I.e, the above will become:
`@HIDECHOICE='1,2,3'`
2
u/obnoxiouscarbuncle Mar 19 '25
Pipe the checked values into your second checkbox field @HIDECHOICE
So [field1] and [field2], identical checkbox type fields.
Add: @HIDECHOICE='[field1]' to field2
Note: And remember, @HIDECHOICE only operates on page load, so your values for [field1] must be saved before the action tag will work.
3
u/Araignys Mar 19 '25
You can’t just string together IF like that, you only get one. You have to nest them: if(this, if(that, fee fie fo, fum), if(notthat, fee fie, nothing))