# ODK calculations: empty integer evaluate to 0

**URL:** <https://forum.communityhealthtoolkit.org/t/odk-calculations-empty-integer-evaluate-to-0/1382>\
**Category:** Technical Support\
**Created:** [July 29, 2021, 1:38pm UTC](https://forum.communityhealthtoolkit.org/t/odk-calculations-empty-integer-evaluate-to-0/1382 "2021-07-29T13:38:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![raf](https://communityhealthtoolkit.b-cdn.net/letter_avatar_proxy/v4/letter/r/848f3c/32.png) [@raf](https://forum.communityhealthtoolkit.org/u/raf)\
**Post date:** [July 29, 2021, 1:38pm UTC](https://forum.communityhealthtoolkit.org/t/odk-calculations-empty-integer-evaluate-to-0/1382/1 "2021-07-29T13:38:28Z")

</div>

Migrating from ODK based platforms, I have realized that some calculations are differently handled in CHT.

For instance an empty integer is evaluated to zero.  
If I have an integer, say height, and have a calculation later on that checks for instance if a child is smaller than a threshold:  
${height}\<90

This is evaluated to TRUE.

In ODK it would be FALSE because ${height} is empty. See also here in [ODK docs](https://docs.getodk.org/form-logic/#empty-values)

CHT equals an empty integer with 0

Could you point me to a reference, documentation where those differences are mentioned so I can adapt my XLS forms?

Many thanks.

---

<div class="post-metadata">

**Author:** ![jkuester](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/jkuester/32/806_2.png) [@jkuester](https://forum.communityhealthtoolkit.org/u/jkuester)\
**Post date:** [July 29, 2021, 3:36pm UTC](https://forum.communityhealthtoolkit.org/t/odk-calculations-empty-integer-evaluate-to-0/1382/2 "2021-07-29T15:36:28Z")

</div>

@raf thank you for bringing this up!

This behavior seems to be a bug in the CHT. I have logged a new issue: [Empty integer values in Enketo forms evaluate to 0 · Issue #7222 · medic/cht-core · GitHub](https://github.com/medic/cht-core/issues/7222) where I note that it is possible this is fixed by our pending [enketo upgrade](https://github.com/medic/cht-core/issues/6345).

Generally speaking, I think the goal is for CHT to properly implement the ODK spec with no surprising differences to the base functionality. The CHT _adds_ some additional functionality that can be leveraged by forms (documented [here](https://docs.communityhealthtoolkit.org/apps/reference/forms/app/)), but I do not know of any behavior differences from the basic ODK functionality that are intentionally included in the CHT.

---

<div class="post-metadata">

**Author:** ![raf](https://communityhealthtoolkit.b-cdn.net/letter_avatar_proxy/v4/letter/r/848f3c/32.png) [@raf](https://forum.communityhealthtoolkit.org/u/raf)\
**Post date:** [July 29, 2021, 4:05pm UTC](https://forum.communityhealthtoolkit.org/t/odk-calculations-empty-integer-evaluate-to-0/1382/3 "2021-07-29T16:05:40Z")

</div>

Dear @jkuester,  
Thank you for helping me out. While waiting for this to be fixed, I have applied this workaround. It might be useful to someone else.  
as `${height} < 90` evaluates to `true` if `height` is empty, one must write

```auto
${height} < 90 and ${height}!=''

```

to get the same behaviour as in ODK.

---

<div class="post-metadata">

**Author:** ![raf](https://communityhealthtoolkit.b-cdn.net/letter_avatar_proxy/v4/letter/r/848f3c/32.png) [@raf](https://forum.communityhealthtoolkit.org/u/raf)\
**Post date:** [July 30, 2021, 9:19am UTC](https://forum.communityhealthtoolkit.org/t/odk-calculations-empty-integer-evaluate-to-0/1382/4 "2021-07-30T09:19:52Z")

</div>

Dear @jkuester,  
as you told me that CHT is supposed to implement ODK specs 1:1 (and then building on top of it), let me mention another discrepancy that I have detected:  
CHT fails to execute calculations that start with a negative number.  
For instance, if we have a variable `var1`and we have a `calculate` field with the following formula:  
`-5 * ${var1} + 20`, then it will not be executed, and the form does not load.

One must write `20 - 5 * ${var1}` for it to work.

Best regards.

---

<div class="post-metadata">

**Author:** ![derick](https://communityhealthtoolkit.b-cdn.net/user_avatar/forum.communityhealthtoolkit.org/derick/32/78_2.png) [@derick](https://forum.communityhealthtoolkit.org/u/derick)\
**Post date:** [July 30, 2021, 9:46am UTC](https://forum.communityhealthtoolkit.org/t/odk-calculations-empty-integer-evaluate-to-0/1382/5 "2021-07-30T09:46:30Z")

</div>

@raf this seems related to this [issue](https://github.com/enketo/openrosa-xpath-evaluator/issues/52) which is fixed in openrosa-xpath-evaluator v2. CHT is currently on the 1.x release but should be upgraded once [this](https://github.com/medic/cht-core/issues/6345) lands.

---

<div class="post-metadata">

**Author:** ![raf](https://communityhealthtoolkit.b-cdn.net/letter_avatar_proxy/v4/letter/r/848f3c/32.png) [@raf](https://forum.communityhealthtoolkit.org/u/raf)\
**Post date:** [July 30, 2021, 9:47am UTC](https://forum.communityhealthtoolkit.org/t/odk-calculations-empty-integer-evaluate-to-0/1382/6 "2021-07-30T09:47:48Z")

</div>

Hi @derick,  
Thank you very much for this info, that sounds great!
