Performing calculations only if fields are "empty"

4132
8
Jump to solution
03-09-2018 11:51 AM
by Anonymous User
Not applicable

Dear Survey123 community,

I have a couple of "dateTime" questions with calculations alongside them to assist users.

And in some case the users may manually overwrite these values before submitting.

But, if an user were to view one of those surveys from their 'inbox or sent folder,' it'll display the calculated value, rather than what was submitted.

So, I was wondering whether it is possible to ONLY perform a calculation, if the respective field is empty.

Attached below is a sample calculation.

date-time(decimal-date-time(today()) + 15.29166669)

Thanks,

Gee

1 Solution

Accepted Solutions
deleted-user-PF38P_WNl02r
New Contributor II

I got something like this working by putting if(string-length(respective field)=0,do time calculation, respective field) in the calculation column of the question I wanted calculated.  In your simple calculation it would be if(string-length(${respectiveFieldName})=0,date-time(decimal-date-time(today()) + 15.29166669),${respectiveFieldName}).  This would make it so the calculated field would do the calculation if the respective field is empty otherwise if the user were to overwrite the respective field it would display the overwrite they did. I hope this helps.

View solution in original post

8 Replies
deleted-user-PF38P_WNl02r
New Contributor II

I got something like this working by putting if(string-length(respective field)=0,do time calculation, respective field) in the calculation column of the question I wanted calculated.  In your simple calculation it would be if(string-length(${respectiveFieldName})=0,date-time(decimal-date-time(today()) + 15.29166669),${respectiveFieldName}).  This would make it so the calculated field would do the calculation if the respective field is empty otherwise if the user were to overwrite the respective field it would display the overwrite they did. I hope this helps.

by Anonymous User
Not applicable

It works

THANKS so much

by Anonymous User
Not applicable

Thanks again for the solution.

But, is there a way to make both - calculated and respective fields the same?

I currently get an error when I try and do this.

Thanks,

Gee

0 Kudos
by Anonymous User
Not applicable

Ismael ChiviteJames Tedrick

Do you guys know if it possible to keep calculated and respective fields the same with the above equation?

Thanks,

Gee

0 Kudos
by Anonymous User
Not applicable

Hi Geethaka,

Can you share a copy of your xlsx form and the error you are getting?

Phil.

0 Kudos
by Anonymous User
Not applicable

Thanks Phil, for getting back to me so quickly.

Copies of my "xlsx form/error message" are attached above.

Thanks,

Gee

0 Kudos
by Anonymous User
Not applicable

Hi Geethaka,

The issue is that you are using the string-length(${startDate}) calculation on the same field ${startDate}. This creates a dependency cycle as there is no answer in ${startDate} until it is selected but you are trying to run a calculation on it before it is selected.

The string-length(${startDate}) would need to be in a following question and reference the previous question, and you can could use null field types to achieve what you are after with your calculations. Using calculations and relevance on the same question is ok, provided you don't create a dependency cycle by trying to run a calculation on the same field the input is required from.

Phil.

0 Kudos
by Anonymous User
Not applicable

Thanks Phil for the explanation.

Gee

0 Kudos