Problems with @CALCTEXT and nested 'if' statements

81 views
Skip to first unread message

kenm...@gmail.com

unread,
May 20, 2025, 10:32:37 AMMay 20
to Redcap Open
I have the following CALTEXT field that says it is valid when the expression is entered in the calculation equation field, but says 'CALCULATION ERRORS EXIST ...' when displaying the form. Here is the expression:

@CALCTEXT(if([visit_1_screening_arm_1][demo_age] >= 25 and [visit_1_screening_arm_1][demo_age] < 30, '25 years',
          if([visit_1_screening_arm_1][demo_age] >= 30 and [visit_1_screening_arm_1][demo_age] < 35, '30 years',
          if([visit_1_screening_arm_1][demo_age] >= 35 and [visit_1_screening_arm_1][demo_age] < 40, '35 years',
          if([visit_1_screening_arm_1][demo_age] >= 40 and [visit_1_screening_arm_1][demo_age] < 45, '40 years',
          if([visit_1_screening_arm_1][demo_age] >= 45 and [visit_1_screening_arm_1][demo_age] < 50, '45 years',
          if([visit_1_screening_arm_1][demo_age] >= 50 and [visit_1_screening_arm_1][demo_age] < 55, '50 years',
          if([visit_1_screening_arm_1][demo_age] >= 55 and [visit_1_screening_arm_1][demo_age] < 60, '55 years',
          '60 years')
          )))))))

There are six calculated fields that need to be filled out with similar age checks to provide a value. Please let me know if you see anything here...

David Edwards

unread,
May 20, 2025, 11:55:31 AMMay 20
to kenm...@gmail.com, Redcap Open
Hi,

I'm a bit rusty on REDCap, but I can't see anything obviously wrong with that.

Only possible things I can think of checking are:

  • The name of your arm and field are correct (but I guess they must be if it's showing as valid in the calculation equation field)

  • Putting single quotes around the numbers, e.g. (if([visit_1_screening_arm_1][demo_age] >= '25' and [visit_1_screening_arm_1][demo_age] < '30',

  • Putting brackets around the conditions, e.g.  @CALCTEXT(if(([visit_1_screening_arm_1][demo_age] >= 25 and [visit_1_screening_arm_1][demo_age] < 30), '25 years',

Sod's law though, probably none of that will make a difference!

Good luck,
David.

From: redca...@googlegroups.com <redca...@googlegroups.com> on behalf of kenm...@gmail.com <kenm...@gmail.com>
Sent: 20 May 2025 14:32
To: Redcap Open <redca...@googlegroups.com>
Subject: [REDCap Open] Problems with @CALCTEXT and nested 'if' statements
 
--
You received this message because you are subscribed to the Google Groups "Redcap Open" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redcap_open...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/redcap_open/4d6dd082-66d5-455f-89cc-f396f6b1cefdn%40googlegroups.com.

David Edwards

unread,
May 20, 2025, 12:08:39 PMMay 20
to kenm...@gmail.com, Redcap Open
... p.s. The only other thing I can think of is removing the carriage returns so it's all on one continuous line. Again, it's clutching at straws though really.

From: redca...@googlegroups.com <redca...@googlegroups.com> on behalf of kenm...@gmail.com <kenm...@gmail.com>
Sent: 20 May 2025 14:32
To: Redcap Open <redca...@googlegroups.com>
Subject: [REDCap Open] Problems with @CALCTEXT and nested 'if' statements
 

kenm...@gmail.com

unread,
May 20, 2025, 5:28:58 PMMay 20
to Redcap Open
Appreciate your thoughts. I don't know what I was thinking when I posted this as I have solved it. My problem was with the field type I selected. Once I changed it to a short text field, it worked...

David Edwards

unread,
May 20, 2025, 5:50:20 PMMay 20
to kenm...@gmail.com, Redcap Open
Oh well - we've all been there! It's good of you to let us know what the problem was.

Sent: 20 May 2025 21:28
To: Redcap Open <redca...@googlegroups.com>
Subject: Re: [REDCap Open] Problems with @CALCTEXT and nested 'if' statements
 
Reply all
Reply to author
Forward
0 new messages