# Error with 'count-non-empty'

**URL:** <https://forum.getodk.org/t/error-with-count-non-empty/23076>\
**Category:** Support\
**Tags:** odk-collect\
**Created:** [November 1, 2019, 1:40pm UTC](https://forum.getodk.org/t/error-with-count-non-empty/23076 "2019-11-01T13:40:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![spono](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/spono/32/8861_2.png) [@spono](https://forum.getodk.org/u/spono)\
**Post date:** [November 1, 2019, 1:40pm UTC](https://forum.getodk.org/t/error-with-count-non-empty/23076/1 "2019-11-01T13:40:31Z")

</div>

Hi all,  
I have a form with a `repeat_group` where I collect some information among which there's the height (cm, integer) and weight (kg, decimal) of my target.  
At the end of the repeat, I would like to calculate automatically the average of the group for both the variables, so I added a `calculate` field using `sum(${field}) div count(${field})`.  
Due to the fact that the `weight` field is not mandatory, I use `count-non-empty()` instead of `count()` but I get the following validation error message from XLSForm online:

> Error: b"ODK Validate Errors:\n\>\> Something broke the parser. See above for a hint.\nError evaluating field 'weight\_mean': The problem was located in calculate expression for ${weight\_mean}\nXPath evaluation: type mismatch \nconverting to numeric\nCaused by: org.javarosa.xpath.XPathTypeMismatchException: The problem was located in calculate expression for ${weight\_mean}\nXPath evaluation: type mismatch \nconverting to numeric\n\t... 11 more\n\nThe following files failed validation:\n${test}.xml\n\nResult: Invalid"

I read around the forum and found [this](https://forum.getodk.org/t/validate-issue-for-decimal-date-time/17710/5).  
I tested a bit trying different approaches, among which using `sum(coaleasce(${field},0))` but I get another error (i.e. not a nodeset). So this let's me think about a possible bug related to `count-non-empty()` or something else related to `decimal()`. Any idea or suggestions?

I'm using version 1.24 .

Attached an example form.  
[test.xlsx](https://forum.getodk.org/uploads/short-url/5pEehesJ0FFedEfcgKPGbhzYBrW.xlsx) (49.7 KB)

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Alexander\_Torrado](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/alexander_torrado/32/2720_2.png) [@Alexander\_Torrado](https://forum.getodk.org/u/Alexander_Torrado)\
**Post date:** [November 3, 2019, 12:58pm UTC](https://forum.getodk.org/t/error-with-count-non-empty/23076/2 "2019-11-03T12:58:05Z")

</div>

Hi @spono,

I haven´t used count-non-empty before so I do not it error you got it is a current bug or misused. Perhaps @LN could confirm about this.

Workaround I use to count non empty is just to include an if(${question\_in\_repeats} !='' then set as 1 otherwise 0 and out of repeat group just sum 1s:

 ![image](https://getodk.b-cdn.net/uploads/default/original/2X/b/b403727a864abcbd81bb91ea5e8fa58648bcac6d.png)  
You can see this form in [sandbox](https://sandbox.aggregate.opendatakit.org/Aggregate.html#management/forms///) as TestConteo

---

<div class="post-metadata">

**Author:** ![Grzesiek2010](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/grzesiek2010/32/2881_2.png) [@Grzesiek2010](https://forum.getodk.org/u/Grzesiek2010)\
**Post date:** [November 4, 2019, 10:14am UTC](https://forum.getodk.org/t/error-with-count-non-empty/23076/3 "2019-11-04T10:14:20Z")

</div>

Hi @spono

thanks for reporting the issue. I took a look at it and the first problem is with the converter which can't handle that function. I reported the issue here: [https://github.com/XLSForm/pyxform/issues/391](https://github.com/XLSForm/pyxform/issues/391)  
You could try to convert the form without that function and the add it manually to an xml version but unfortunately there is also a bug in Javarosa which I reported here: [https://github.com/opendatakit/javarosa/issues/509](https://github.com/opendatakit/javarosa/issues/509)

We will try to fix it.

---

<div class="post-metadata">

**Author:** ![spono](https://getodk.b-cdn.net/user_avatar/forum.getodk.org/spono/32/8861_2.png) [@spono](https://forum.getodk.org/u/spono)\
**Post date:** [November 5, 2019, 10:24am UTC](https://forum.getodk.org/t/error-with-count-non-empty/23076/4 "2019-11-05T10:24:42Z")

</div>

Perfect, good to know @Grzesiek2010!  
I'll take a look to @Alexander_Torrado's solution in the meantime.

Thanks a lot both for the support!
