Maria Bromberg
Maria Bromberg

Reputation: 1

Referencing repeating instance in calculated field

I'm trying to write a formula for a calculated field in a repeating instrument to calculate (pull data from) a field in a different repeating instrument; I need the formula to reference any of the instances, not just a specific one and the available smart variable options (e.g. current-instance, next-instance) don't seem to address this need.

The formula I'm trying to write is along the lines of following (variable 1 is a date in a repeating instance; variable 2 is a date in a different repeating instance; the references I'm trying to/unable to code are in all caps)

if([variable1][current-instance]=[variable2][ANY-INSTANCE], [variable3][FROM SAME INSTANCE AS VARIABLE2],"na")`

In other words, there a way to tell REDCap to 'look for match in these variables in any existing instance and return a third variable if found'?

I tested to make sure I have date formats set up correctly by referencing specific instances, e.g.:

if([variable1][1]=[variable2][1], [variable3][1], "na")

This formula returns the correct value, but I don't want to have to specify the instance number (instead I want to formula to 'look for' any instance to find a match).

The same formula without references to a specific instance returns 'no value' (presumably because REDCap is looking at only the first instance of each repeating instrument).

Upvotes: 0

Views: 1841

Answers (1)

Malcolm
Malcolm

Reputation: 1

OK, so I've found a way.. and it's a wee bit ugly. So, you can reference a specific "instance" of a variable within a repeating instance using the following; [variable][1] [variable][2] etc so you can reference all the instances But, importantly, you can reference instances that don't exist, they are treated as "Empty". So, as long as you have a somewhat limited number of instances, you could formulate the query like; @CALCTEXT(if([variable][1] = 'whatyouwant' or [variable][2]='whatyouwant' or etc etc,'True outcome','False outcome')) Tis a bit scary, but it does work!

Upvotes: 0

Related Questions