31 Dec 2018: Thank you to our knowledgeable and friendly forums users for another great year. We are aware of the uptick in spam accounts and are doing our best to ban these at first sight. Thank you for your patience!

If Then Else

Hello everyone,

in the forum I saw the solution how to use the decode function in order to build the If-Then-Else equivalent. This works great if field1 is only one value (NULL, 1, 2, etc.).

(IF field1 is NULL THEN field2 = "0" ELSE field2 = "1")   --->   func: decode(field1,NULL,0,1)
see: https://www.openclinica.com/forums#/discussion/7384/if-then-statements-in-calculated-fields

Is it possible to test something like that:

(IF field1 < value1 THEN field2 = "0" ELSE field2 = "1")   --->   func: decode(field1, lt(value1), 0, 1)  ---> doesn't work
(IF field1 < value1 or field1 >= value2 THEN field2 = "0" ELSE field2 = "1")
(IF (field1 between value1 and value2 or field1 < value 3) and field2 >= value4 THEN field2 = "0" ELSE field2 = "1")

I hope someone can help.



  • haenselhaensel Posts: 602 ✭✭✭
    via Email
    Hi Philipp

    It is not possible to achieve this with the decode function.

    Option 1:
    Rules are designed for elaborated features like this (e.g with

    Option 2:
    Calculating field values using embedded JavaScript has been discussed in
    the past quit often (I have no link at hand).

  • PSeboekPSeboek Posts: 3
    Thanks Christian for your answer!
    I'll try it out.
This discussion has been closed.