Displaying value based on recorded interview date landing between a range of dates

I’d like to be able to display a single numeric value from 1 to 4, representing quarters, based on which date range the selected date of interview falls between.
Where,
Quarter 1 would be Jan 1 to Mar 31.
Quarter 2: Apr 1 to Jun 30
Quarter 3: Jul 1 to Sep 30
Quarter 4: Oct 1 to Dec 31

So if the date of interview recorded is ‘2022-01-19’, it should display a ‘1’ representing first Quarter.

Hi @jgordontoylor, here’s one way of doing this using several calculate question types and the coalesce() method:

survey

type name label calculation
date date The date
calculate q1 if(${date} >= ‘2022-01-01’ and ${date} <= ‘2022-03-31’, 1, ‘’)
calculate q2 if(${date} >= ‘2022-04-01’ and ${date} <= ‘2022-06-30’, 2, ‘’)
calculate q3 if(${date} >= ‘2022-07-01’ and ${date} <= ‘2022-09-30’, 3, ‘’)
calculate q4 if(${date} >= ‘2022-10-01’ and ${date} <= ‘2022-12-31’, 4, ‘’)
calculate q coalesce(coalesce(${q1}, ${q2}), coalesce(${q3}, ${q4}))
note n Quarter: ${q}

Or maybe more simply using the concat() method:

survey

type name label calculation
date date The date
calculate q1 if(${date} >= ‘2022-01-01’ and ${date} <= ‘2022-03-31’, 1, ‘’)
calculate q2 if(${date} >= ‘2022-04-01’ and ${date} <= ‘2022-06-30’, 2, ‘’)
calculate q3 if(${date} >= ‘2022-07-01’ and ${date} <= ‘2022-09-30’, 3, ‘’)
calculate q4 if(${date} >= ‘2022-10-01’ and ${date} <= ‘2022-12-31’, 4, ‘’)
calculate q concat(${q1}, ${q2}, ${q3}, ${q4})
note n Quarter: ${q}
1 Like

It works. Thanks much!

2 Likes

Hello @jgordontoylor,
You might also combine the calculations from Josh in a single cascading one: if(…, , if(…, , if(…, , if(…, . “unknown”) ))).

3 Likes

In this combination add “OR”?

Welcome to the community, @Neves! Yes, the boolean operators or is also supported. But you must fit into the expression to use it as expected.

Hi @Josh
I am facing a similar question, however, the methods you proposed would only work if the year of reference is 2022. Is there a way to make the ‘calculate’ function extracts only the information about the month regardless of the year?
I would like to use this group of command also for the years to come.
Many thanks,
Lavinia