# Field Calculation

**URL:** <https://forum.getodk.org/t/field-calculation/1971>\
**Category:** Support\
**Created:** [February 20, 2013, 8:05am UTC](https://forum.getodk.org/t/field-calculation/1971 "2013-02-20T08:05:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chan\_Choth](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/c/c67d28/32.png) [@Chan\_Choth](https://forum.getodk.org/u/Chan_Choth)\
**Post date:** [February 20, 2013, 8:05am UTC](https://forum.getodk.org/t/field-calculation/1971/1 "2013-02-20T08:05:12Z")

</div>

Dear all,

These are all the steps I put to calculate the fields. All are unsuccessful.

1. Create a calculate type and do the  
calculation ${bt\_total}-${bt\_unimproved}
2. Put the formula directly into the fields and in the constraint .  
\<=${tp\_total}-${pour\_flush}

Please see the attached file for more information. Could you please help me  
how could I do this?

Thanks,  
Chan Choth

[GSF\_Commune\_DB.xls](https://getodk.b-cdn.net/uploads/default/original/1X/4f48486655c9950a52275d6bf9c9ce620e232ae7.xls) (33 KB)

---

<div class="post-metadata">

**Author:** ![Nathan](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/n/c5a1d2/32.png) [@Nathan](https://forum.getodk.org/u/Nathan)\
**Post date:** [February 20, 2013, 7:10pm UTC](https://forum.getodk.org/t/field-calculation/1971/2 "2013-02-20T19:10:20Z")

</div>

Hi Chan,  
I believe you can make your formulas work by adding spaces around your  
${variables}. So, for example, the calculation "${bt\_total} -  
${bt\_unimproved}" should work. In the future, I'll look into padding the  
generated xpaths with spaces automatically so this kind of thing doesn't  
happen.  
Regards,  
-Nathan

> **···**
>
> On Wednesday, February 20, 2013 12:05:12 AM UTC-8, Chan Choth wrote: \> \> Dear all, \> \> These are all the steps I put to calculate the fields. All are \> unsuccessful. \> \> 1) Create a calculate type and do the \> calculation ${bt\_total}-${bt\_unimproved} \> 2) Put the formula directly into the fields and in the constraint . \> \<=${tp\_total}-${pour\_flush} \> \> Please see the attached file for more information. Could you please help \> me how could I do this? \> \> Thanks, \> Chan Choth \>

---

<div class="post-metadata">

**Author:** ![Chan\_Choth](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/c/c67d28/32.png) [@Chan\_Choth](https://forum.getodk.org/u/Chan_Choth)\
**Post date:** [February 21, 2013, 3:17am UTC](https://forum.getodk.org/t/field-calculation/1971/3 "2013-02-21T03:17:45Z")

</div>

Hi Nathan,

Thanks, it works now. I am looking forward for this future improvement that  
you mentioned below.

Best regards,  
Chan Choth

> **···**
>
> On Thursday, February 21, 2013 2:10:20 AM UTC+7, Nathan wrote: \> \> Hi Chan, \> I believe you can make your formulas work by adding spaces around your \> ${variables}. So, for example, the calculation "${bt\_total} - \> ${bt\_unimproved}" should work. In the future, I'll look into padding the \> generated xpaths with spaces automatically so this kind of thing doesn't \> happen. \> Regards, \> -Nathan \> \> On Wednesday, February 20, 2013 12:05:12 AM UTC-8, Chan Choth wrote: \>\> \>\> Dear all, \>\> \>\> These are all the steps I put to calculate the fields. All are \>\> unsuccessful. \>\> \>\> 1) Create a calculate type and do the \>\> calculation ${bt\_total}-${bt\_unimproved} \>\> 2) Put the formula directly into the fields and in the constraint . \>\> \<=${tp\_total}-${pour\_flush} \>\> \>\> Please see the attached file for more information. Could you please help \>\> me how could I do this? \>\> \>\> Thanks, \>\> Chan Choth \>\> \>

---

<div class="post-metadata">

**Author:** ![Nathan](https://getodk.b-cdn.net/letter_avatar_proxy/v4/letter/n/c5a1d2/32.png) [@Nathan](https://forum.getodk.org/u/Nathan)\
**Post date:** [February 22, 2013, 10:16pm UTC](https://forum.getodk.org/t/field-calculation/1971/4 "2013-02-22T22:16:29Z")

</div>

Hi Chan,  
I've updated the [opendatakit.org](http://opendatakit.org) XLSForm converter so adding spaces around  
variables should no longer be necessary.  
Regards,  
-Nathan
