IF Statement related challenge

I want to achieve the following:

  1. When I select Visit1 from the “Select Visit” list and provide any given date, it should add five (5) days to the Date.
  2. When Visit2, Visit3 or Visit6 is selected, it adds five (5) days to the selected Date.
  3. 40 days is added to Visit4 and Visit7
  4. 169 days added to Visit5
  5. 351 days added to Visit8
    I have written an “if” statement but I only get the last part of my code working. I need help.
    Thank you.
    Note! Visit1 to Visit9 is a dropdown list
    Sample Work.xlsx (8.5 KB)

Hello,

Your if logic seems ok.

You do not need the date function inside the if and in an if argument a function does not need accents. Also, a variable should start with lower case. A simplified functional version of your condition is

date(if((${visit}='visit1'), ${date}+5, ${date}+10))

The encompassing date() function changes the integer back into a date

See https://docs.getodk.org/form-operators-functions/#converting-dates-and-time

Bert

2 Likes

@Logout.
Write something like this based on your needs
if(selected(${visit},'1'),date-time(decimal-date-time(${date})+90),
if(selected(${visit},'2'),date-time(decimal-date-time(${date})+180),
if(selected(${visit},'3'),date-time(decimal-date-time(${date})+270),
if(selected(${visit},'7'),date-time(decimal-date-time(${date})+365),
if(selected(${visit},'4'),date-time(decimal-date-time(${date})+450),
if(selected(${visit},'5'),date-time(decimal-date-time(${date})+540),
if(selected(${intmonth},'6'),date-time(decimal-date-time(${date})+630),'None')))))))

Thanks for your help. :blush:

Thanks for your help @Derick_Deo :slightly_smiling_face: