Answer auto-selected based on date

333
2
Jump to solution
10-23-2019 05:50 AM
JasonCyphers
Occasional Contributor III

I have a daily, weekly, monthly, quarterly, bi-annual, and annual inspection that is performed on an asset.  I'd like the default inspection type to be daily but then be defaulted to weekly every Friday, monthly on the first Friday of every month the month, quarterly every third month, etc.

Is there a way to do this through some sort of 'if' statement in Survey123?

0 Kudos
1 Solution

Accepted Solutions
JamesTedrick
Esri Esteemed Contributor

Hi Jason,

Yes this is possible, but would be a little complex and also needs a little more information in for the quarterly/semi-annual criteria (which month should the inspection be in of the quarter).

To model this out, let's assume the quarterly inspections occur on the 1st month of quarter based on the calendar year (i.e., January, April, July, October), semi-annual in July and the annual in January, all on the first Friday of the month

DayForm Type
Saturday - Thursday (i.e., not Friday)Daily
Friday (not 1st Friday -> day > 7)Weekly
Friday (1st Friday -> day <=7)Monthly
Friday (1st Friday of -> day <=7, 1 month of the quarter)Quarterly
Friday (1st Friday of -> day <=7, month of June)Semi-annual
Friday (1st Friday of -> day <=7, month of January)Annual

As you might guess from the multiple criteria, multiple (nested) if() statements will be needed.  The day of the week can be determined from format-date(${dateQ},'%a'), which gives the 3 letter abbreviation of the day:

if( format-date(${dateQ},'%a') != 'Fri', 'daily', ...)

Adding in the weekly is comparison of the weekday (which can be retrieved by int(format-date(${dateQ},'%e')):

if( format-date(${dateQ},'%a') != 'Fri', 'daily', if(int(format-date(${dateQ},'%e')) > 7, 'weekly', ... ))

The separation between Monthly, Quarterly, Semi-annual and annual look at the month value int(format-date(${dateQ}, '%n')):

if( format-date(${dateQ},'%a') != 'Fri', 'daily', if(int(format-date(${dateQ},'%e')) > 7, 'weekly', if(int(format-date(${dateQ}, '%n')) = 1, 'annual', if(int(format-date(${dateQ}, '%n')) = 7, 'semiannual', if(int(format-date(${dateQ}, '%n')) = 4 or int(format-date(${dateQ}, '%n')) = 10, 'quarterly', 'monthly')))))

View solution in original post

2 Replies
JamesTedrick
Esri Esteemed Contributor

Hi Jason,

Yes this is possible, but would be a little complex and also needs a little more information in for the quarterly/semi-annual criteria (which month should the inspection be in of the quarter).

To model this out, let's assume the quarterly inspections occur on the 1st month of quarter based on the calendar year (i.e., January, April, July, October), semi-annual in July and the annual in January, all on the first Friday of the month

DayForm Type
Saturday - Thursday (i.e., not Friday)Daily
Friday (not 1st Friday -> day > 7)Weekly
Friday (1st Friday -> day <=7)Monthly
Friday (1st Friday of -> day <=7, 1 month of the quarter)Quarterly
Friday (1st Friday of -> day <=7, month of June)Semi-annual
Friday (1st Friday of -> day <=7, month of January)Annual

As you might guess from the multiple criteria, multiple (nested) if() statements will be needed.  The day of the week can be determined from format-date(${dateQ},'%a'), which gives the 3 letter abbreviation of the day:

if( format-date(${dateQ},'%a') != 'Fri', 'daily', ...)

Adding in the weekly is comparison of the weekday (which can be retrieved by int(format-date(${dateQ},'%e')):

if( format-date(${dateQ},'%a') != 'Fri', 'daily', if(int(format-date(${dateQ},'%e')) > 7, 'weekly', ... ))

The separation between Monthly, Quarterly, Semi-annual and annual look at the month value int(format-date(${dateQ}, '%n')):

if( format-date(${dateQ},'%a') != 'Fri', 'daily', if(int(format-date(${dateQ},'%e')) > 7, 'weekly', if(int(format-date(${dateQ}, '%n')) = 1, 'annual', if(int(format-date(${dateQ}, '%n')) = 7, 'semiannual', if(int(format-date(${dateQ}, '%n')) = 4 or int(format-date(${dateQ}, '%n')) = 10, 'quarterly', 'monthly')))))

JasonCyphers
Occasional Contributor III

Thank you so much James.  This is perfect!

0 Kudos