Creating a new variable within a form based on previous selection

Hello,

I have a form with a select date variable, using the yyyy format. Based on the year that they select, I would like to create a new (preferably hidden) variable that generates this selection in the format of a two year range (e.g. yyyy-yyyy) with the first year in the range being the one selected in the previous question. I could manipulate the data set after exporting using a different software, but it would easier to add a calculate question within the form so that the new variable exists prior to exporting. Is this possible?

Example:

  1. Please select the year:
    2021

  2. Season (auto-calculated):
    2021-2022

Thanks!

Hi @caratupps,

Following these steps should work:

  • Convert your year to decimal-date-time(),
  • Create a calculate question and add the needed days to the decimal mentioned above
  • Reconvert to year with date()

Here is more information from ODK Docs, about the functions I mentioned:

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

1 Like

@caratupps, should the auto-calculated value be a +1 of any year the user enters in Q1? e.g. if a user enters 2025 in Q1 the auto-calculated value should be 2025-2026 in Q2.

@Kal_Lam Yes, that’s correct.

Hi @hakan_cetinkaya. Thanks for the suggestion, but I don’t really understand the process after reading about the functions. Is it possible to do this within form builder or would I need to make my own formula in the calculation column of the xls form? Would the formula be nested, as in date(calculate(decimal-date-time(question_1)+365))?