Calculation fails

2064
4
10-12-2016 03:29 AM
Nicole_Ueberschär
Esri Regular Contributor

If someone can suggest a better title for my question, please feel free to...

I have a problem with the calculation of a field (or with it's result, I don't know):

I have four fields. Not all of them have to be filled but the total has to be 100. To check for this constraint I added a new field (as a text field, also tried as integer field) that adds up the values of these 4 fields (in the calculate attribute):

number(${landuse_share_1})+number(${landuse_share_2})+number(${landuse_share_3})+number(${landuse_share_4}) 

and writes it into the new field ${total}. In the constraint field I say ${total}=100 (also tried ${total}="100").

Now in Connect all of my tests worked well but when I try the same on a tablet or my phone (both Android) it seems like the calculation is not performed. Neither is my text/integer field filled nor does the survey accept my values but reminds me that the total has to be 100. The same with Survey123 on my windows computer. 

In Connect it shows me straight away a 0 in that field (when Integer), where I expect my total to appear. In the apps, there is just nothing. 

Any idea?

Tags (1)
0 Kudos
4 Replies
WengNg
by
New Contributor III

Hi Nicole,

Not sure what the issue is here. Here is an attached sample that I created based on what you have described above. I

The calculations seems to be working to me.

Regards,

Weng

0 Kudos
Nicole_Ueberschär
Esri Regular Contributor

So, I think I see now where the problem is. 

When the input fields are set as text everything works fine, also when not all fields are filled. 

When the input fields are set as integers (which would make sense in this context), it is working as long as all fields are filled, but not any more when some are left empty. The problem is the way an empty integer field is saved (NaN) in contrast to an empty text field being just "". 

In connect it seems to be working also with Integer fields, but not in the app. 

Since I want the people only to enter numbers I did a workaround now with additional fields checking first if the fields are not empty and calculating then the result of those check fields: 

typenamelabelcalculation
integerlanduse_share_1landuse_share_1
integerlanduse_share_2landuse_share_2
integerlanduse_share_3landuse_share_3
integerlanduse_share_4landuse_share_4
hiddenlu1_txtlu1_txtif(${landuse_share_1}>0,${landuse_share_1},0)
hiddenlu2_txtlu2_txtif(${landuse_share_2}>0,${landuse_share_2},0)
hiddenlu3_txtlu3_txtif(${landuse_share_3}>0,${landuse_share_3},0)
hiddenlu4_txtlu4_txtif(${landuse_share_4}>0,${landuse_share_4},0)
noteshow_textAll_values${lu1_txt} +", "+${lu2_txt}+", "+${lu3_txt}+", "+${lu4_txt}
integertotaltotalnumber(${lu1_txt})+number(${lu2_txt})+number(${lu3_txt})+number(${lu4_txt})

Maybe this helps also someone else with a similar problem...

WengNg
by
New Contributor III

That is an interesting behaviour. I would expect the sum to ignore a null/empty field when a sum is done. You could also set a default value of zero as a potential workaround.

Nicole_Ueberschär
Esri Regular Contributor

That’s in fact also a good idea Weng!

0 Kudos