Default value of 0 not always replaced by user and not included in calculations

462
4
Jump to solution
12-18-2020 12:31 PM
LeonardBarnhill
Occasional Contributor

I have several questions of type decimal with a default value set to "0" (zero). This displays properly on the form but when the user enters a value, sometimes the 0 (zero) is overwritten with the new value and sometimes the 0 remains - the result is 012 instead of 12.  This does not affect calculations in the form when the user modifies the value but is inconsistent for the user.  How do I set this so that it always overwrites the default 0 (zero)?

As a follow up, setting the default value to 0 (zero) also does not work in calculations if the group is not opened.  How can I write the calculation so that the default value of 0 is used even if the group is not opened?

Example; This formula:

${abvgrd} + (${RRDEPTH} * ${RRCOUNT}) + ${FRDEPTH} + ${GRDADJDPT} + ${CONEDEPTH} + ${WALLDEPTH} + ${TRFDEPTH}

works if every field is populated by the user.  But, for the field ${abvgrd} the user does not enter a value if the previous questions is answered "Below Grade".  I thought setting the Above Grade {abvgrd} value to 0 would allow the calculation to complete but apparently there is no 0 applied when Below Grade is selected.

Suggestions?

0 Kudos
1 Solution

Accepted Solutions
DougBrowning
MVP Notable Contributor

Which version are you on?  Defaults not being applied when a field becomes relevant is a bug that has been around awhile.  Sounds like this may be happening to you?  Also when you say group is not opened you mean a relevant?  Any field not relevant gets a '' and no default.

One work around is to use 

coalesce(value1, value2)   Returns the first nonempty value. Supports only two values coalesce(${question_one},${question_two})

So coalesce(${abvgrd},0) + coalesce((${RRDEPTH} * ${RRCOUNT}),0) ...etc

This way if the value is not relevant and '' then you get the 0.

Hope that helps

View solution in original post

4 Replies
DougBrowning
MVP Notable Contributor

Which version are you on?  Defaults not being applied when a field becomes relevant is a bug that has been around awhile.  Sounds like this may be happening to you?  Also when you say group is not opened you mean a relevant?  Any field not relevant gets a '' and no default.

One work around is to use 

coalesce(value1, value2)   Returns the first nonempty value. Supports only two values coalesce(${question_one},${question_two})

So coalesce(${abvgrd},0) + coalesce((${RRDEPTH} * ${RRCOUNT}),0) ...etc

This way if the value is not relevant and '' then you get the 0.

Hope that helps

LeonardBarnhill
Occasional Contributor

Coalesce did the job perfectly.  I had not used coalesce before.  

FYI, I am using v 3.12.195 and I am not positive what you mean by relevant but your suggestion was the fix.  Also, by Group I mean a set of questions the reveal when a preceding question is answered "yes". Thanks

0 Kudos
DougBrowning
MVP Notable Contributor

I assume you are using the relevant column to hide/show the fields.  When they hide they go to "" blank string as the value.  This is what breaks your calc since "" makes no sense.

0 Kudos
PatrickCrushell
New Contributor III

Is this a recent bug - I have a complex form where this seems to be causing many of the calculations to misfire... frustrating that the calcs were working fine all last year... seems like the problem only arise in recent weeks.... Any idea whether it is likely to be fixed?

 

0 Kudos